0

I am developing a site where users choose their city (from a long list), an activity (again a long list) and then a level of expertise. After that, the site shows them local events based upon their choices. I have over 100 POST variables (and more being added). How can this be done in MySQL?

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
Sal P
  • 21
  • 1
  • 1
    Have you thought about using a [database library](http://stackoverflow.com/questions/108699/good-php-orm-library) or a [framework](http://www.phpframeworks.com)? – tadman Oct 10 '12 at 14:11
  • 3
    You should probably come up with a complete specification before doing something like this. If you have a good idea about how these options relate, and how new ones would fit in, a good design pattern would allow you to add in new ones with minimal amount of work. If you already have a full spec, then my advice would be something like a one to many relation between a user and previously selected options. – thatidiotguy Oct 10 '12 at 14:11
  • This is really more of a design/architecture question, and as such it's off-topic for the site. – David Oct 10 '12 at 14:13
  • Everytime for users? and the easiest way? is sounds contradictory i think. – lijinma Oct 10 '12 at 14:17

2 Answers2

0

You only have a few variables (city, activity, expertise). Use a session.

Here is a link to sessions in PHP (sessions)

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • Thanks everyone! I discovered the PHP SERVER and PHP SELF functions which will do the trick with MYSQL. – Sal P Oct 11 '12 at 22:12
0

Yes, you have the right idea. create a table and store each variable you would like to save.

post whatever variables from whatever scripting language of your choice, and the database statement would look something like this:

'INSERT INTO `your_table_name` (`field_1`,`field_2`) VALUES ('$post1','$post2');

you can add more fields as your information grows. That would be the best way to start getting into mysql. Of course this answer is the simplest solution. I recommend you read up on all fun and much more complex things you can do with mysql.

More efficiently I would do it like this:

categorize / classify your post variables and create multiple tables grouping similar things or data from a specific page. Create an auto increment primary id for your rows on the master table of the group, and then join your tables as needed. That's a little more advanced, so I suggest you add your few fields that you currently are using to a table now, and when you need to start adding more, looking these topics:

Normalization: http://en.wikipedia.org/wiki/Database_normalization

Primary Keys, Joins, Stored Procedures, and the list goes on.

Eric Leroy
  • 1,830
  • 1
  • 18
  • 31