Jump to content

An easy way to do this?


eugeniu

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/161399-an-easy-way-to-do-this/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.