eugeniu Posted June 8, 2009 Share Posted June 8, 2009 I'm creating a quiz/flashcard program with somewhere over a hundred questions. The questions are organized into groups of five or less, with each group having an ID. So my database for the questions is like: Question1 | Group# | Answer1 Question2 | Group# | Answer2 Question3 | Group# | Answer3 Et cetera... I'm planning on creating options in my settings page to let the user pick exactly what group he or she wants to receive questions from, and to have those settings saved on their account, in their account entry on the database. My problem is that I don't want to have to make a field for each group on my users table, because I'd then end up with dozens of fields. So is there any way I could define what groups I want to use in one field on a table? Thanks. Quote Link to comment Share on other sites More sharing options...
dawsba Posted June 8, 2009 Share Posted June 8, 2009 Create a table for group types CREATE TABLE `your_database`.`tbl_group_type` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` TEXT NOT NULL ) ENGINE = MYISAM Create a log db for users->groups CREATE TABLE `your_database`.`tbl_groups` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `userid` INT NOT NULL , `groupid` INT NOT NULL ) ENGINE = MYISAM log all the groups into the group_type table and propigate the users table with your information, when your pulling out use somthing similar to SELECT * FROM `tbl_groups` WHERE `userid` = '".$the_user_id."' hope this helps Quote Link to comment Share on other sites More sharing options...
eugeniu Posted June 9, 2009 Author Share Posted June 9, 2009 I'm still a bit confused. There's a difference between a table and a log db, right? Quote Link to comment Share on other sites More sharing options...
dawsba Posted June 9, 2009 Share Posted June 9, 2009 Nothing their both tables, its just me , When describing a database I say a table is static information & a logging db records data(dynamic), but they are both tables, lol dont listen to my excentricities. Quote Link to comment Share on other sites More sharing options...
eugeniu Posted June 9, 2009 Author Share Posted June 9, 2009 Ok, so I make a table that contains the names and IDs of the groups. Then I create a table that has an entry for every group any user has? So if two users had 6 groups selected, there would be 12 entries? Quote Link to comment Share on other sites More sharing options...
dawsba Posted June 9, 2009 Share Posted June 9, 2009 yes, the tbl_group_type table would have all 6 groups and ids and the tbl_groups would have 12 (6per user) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.