![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello I had some very helpful comments in my earlier post but am still struggling to get a better table design. I have made a small step (?) by using an auto increment id in the p2_users table and by using mysql_insert_id() so that the id in the p2_results table is the same. |
|
The situtation for groupname p2 is as follows. There are 12 sections, each with 10 sub-sections and the user can answer any number of sections between 1 and 12. Each sub-section provides 5 pieces of user created data. The p2_user table has the following structure id (auto increment) dt (date/time) name usercode group sub_section The p2_results table has this structure id (copied from p2_users via mysql_insert()) sub_section answer a_order ws whyws delay I can see that I get duplicated data in the two tables but am not sure where to go next.... You can see the p2_users and p2_results data for 2 sections of data at http://www.micro-active.com/p2_users.gif and http://www.micro-active.com/p2_results.gif Any comments please?! Cheers Geoff |
#3
| |||
| |||
|
|
In article <6mp3u65lvr3ovamlkped0j0ek40i18pu5r (AT) 4ax (DOT) com>, geoff (AT) invalid (DOT) invalid wrote: Hello I had some very helpful comments in my earlier post but am still struggling to get a better table design. I have made a small step (?) by using an auto increment id in the p2_users table and by using mysql_insert_id() so that the id in the p2_results table is the same. Why? What purpose does that column serve? |
|
The situtation for groupname p2 is as follows. There are 12 sections, each with 10 sub-sections and the user can answer any number of sections between 1 and 12. Each sub-section provides 5 pieces of user created data. The p2_user table has the following structure id (auto increment) dt (date/time) name usercode group sub_section The p2_results table has this structure id (copied from p2_users via mysql_insert()) sub_section answer a_order ws whyws delay I can see that I get duplicated data in the two tables but am not sure where to go next.... You can see the p2_users and p2_results data for 2 sections of data at http://www.micro-active.com/p2_users.gif and http://www.micro-active.com/p2_results.gif Any comments please?! Cheers Geoff |
#4
| |||
| |||
|
|
On Sun, 29 May 2011 12:24:14 GMT, dougatmilmacdotcom (AT) example (DOT) com (Doug Miller) wrote: In article <6mp3u65lvr3ovamlkped0j0ek40i18pu5r (AT) 4ax (DOT) com>, geoff (AT) invalid (DOT) invalid wrote: Hello I had some very helpful comments in my earlier post but am still struggling to get a better table design. I have made a small step (?) by using an auto increment id in the p2_users table and by using mysql_insert_id() so that the id in the p2_results table is the same. Why? What purpose does that column serve? Doug How cruel ! |
|
It allows the connection between the 2 tables. Not necessary? How should this be done? |
|
Cheers Geoff The situtation for groupname p2 is as follows. There are 12 sections, each with 10 sub-sections and the user can answer any number of sections between 1 and 12. Each sub-section provides 5 pieces of user created data. The p2_user table has the following structure id (auto increment) dt (date/time) name usercode group sub_section The p2_results table has this structure id (copied from p2_users via mysql_insert()) sub_section answer a_order ws whyws delay I can see that I get duplicated data in the two tables but am not sure where to go next.... You can see the p2_users and p2_results data for 2 sections of data at http://www.micro-active.com/p2_users.gif and http://www.micro-active.com/p2_results.gif Any comments please?! Cheers Geoff |
#5
| |||
| |||
|
|
How cruel ! What do you mean, "cruel" ? That's a perfectly legitimate question. |
|
One table is sufficient. Columns would be: username session_ID section_number field_number response |
#6
| |||
| |||
|
|
On Sun, 29 May 2011 14:07:46 GMT, dougatmilmacdotcom (AT) example (DOT) com (Doug Miller) wrote: How cruel ! What do you mean, "cruel" ? That's a perfectly legitimate question. Doug, 'just meant it took me a while to sort out the links between the two tables. |
|
Previously you wrote One table is sufficient. Columns would be: username session_ID section_number field_number response I thought that better design meant that there should be minimum duplication. |
|
Doesn't the above mean that the username and session_ID are repeated on each row? |
#7
| |||
| |||
|
|
You misunderstand. Good design means (among other things) not duplicating *columns* (as you did in your original design, with some 600 columns that all stored the same attribute). |
|
Doesn't the above mean that the username and session_ID are repeated on each row? So what if they are? Username + sessionID + section_number + field_number is a natural primary key for this application. What is the data you are storing? User responses. How is a user response uniquely identified? By the combination of username, sessionID, section number, and field number. One row per response. ONE TABLE. |
#8
| |||
| |||
|
|
On Sun, 29 May 2011 18:45:53 GMT, dougatmilmacdotcom (AT) example (DOT) com (Doug Miller) wrote: Doug, You misunderstand. Good design means (among other things) not duplicating *columns* (as you did in your original design, with some 600 columns that all stored the same attribute). Ah! OK. Doesn't the above mean that the username and session_ID are repeated on each row? So what if they are? Username + sessionID + section_number + field_number is a natural primary key for this application. What is the data you are storing? User responses. How is a user response uniquely identified? By the combination of username, sessionID, section number, and field number. One row per response. ONE TABLE. I should have used sub_section_number and not section_number as there are 12 sections each with 10 sub-sections. Does the number of possible rows matter? |
|
If as above there would be 5 rows for each sub-section. There are 10 sub-sections per section, so 10 x 5 = 50 rows. The user can respond to up to 12 sections so a possible 12 x 50 = 600 rows per session. If we have 100 users that gives a possible 100 x 600 = 60,000 rows. Is the 60,000 rows a problem? |
|
Presumably the sessionID could be INT/auto incremental? |
#9
| ||||
| ||||
|
|
Does the number of possible rows matter? Probably not in your application. All databases have limits on the size to which a table can grow, and any file system has an inherent upper limit on the size of any single file, as well, but it's very unlikely that you're going to encounter them. |
|
http://dev.mysql.com/doc/refman/5.0/en/full-table.html |
|
If as above there would be 5 rows for each sub-section. There are 10 sub-sections per section, so 10 x 5 = 50 rows. The user can respond to up to 12 sections so a possible 12 x 50 = 600 rows per session. If we have 100 users that gives a possible 100 x 600 = 60,000 rows. Is the 60,000 rows a problem? Certainly not. |
|
Presumably the sessionID could be INT/auto incremental? Could be, but why? You're already storing username and date/time -- isn't the timestamp sufficient to uniquely identify a session for any particular user? |
#10
| |||
| |||
|
|
In article<dom4u6lkarubp4bjtk9kg5752t8v77in98 (AT) 4ax (DOT) com>, geoff (AT) invalid (DOT) invalid wrote: On Sun, 29 May 2011 14:07:46 GMT, dougatmilmacdotcom (AT) example (DOT) com (Doug Miller) wrote: How cruel ! What do you mean, "cruel" ? That's a perfectly legitimate question. Doug, 'just meant it took me a while to sort out the links between the two tables. Why do you insist on using two tables? There is *no reason* why you need more than one. |
![]() |
| Thread Tools | |
| Display Modes | |
| |