Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determening values from database 1

Status
Not open for further replies.

rjseals

Technical User
Nov 25, 2002
63
US
I have a form with around 50 check boxes (options are codes for certification). A user will select no more than 4 options.

I have a mysql database. The field names are basically the cert codes (ie 001, 002, 003, 004 etc) When the user selects the appropriate codes from the form page and submit, an X gets put into the database under that field.

What I am trying to do on a results page is to print out the options they selected. So for instance if they picked 004, 005, 112, and 009 I want to be able to list those codes on a separate page. What would be an efficient way to get the records that only have an X in them?

Thanks for any tips or pointers.
 
It depends on how you are storing the information.

If you have a single table with umpteen columns, each of which maps to a checkbox, there is no way. You'll have to fetch all columns and produce output only for those that are checked.

However, I strongly recommend that you not store this information in a single table. Rather I recommend that you store the information pertaining to the checkboxes in a separate, related table. This second table will have two columns: an ID column which is used to relate the data back to the original table, and a column to actually store the data.

To be honest, I'd probably go with three tables: one to store the main user information, one to store all possible choices that can be mapped to checkboxes, and a third to relate records from the two tables.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I think I understand what you are saying but let me make sure. So I have one table with user information (name, address etc), one table with the codes (001, 002, 003) and the third table would have 2 columns one for the user and one for the code?
 
And as to your question:
What would be an efficient way to get the records that only have an X in them?
 

I'd give each checkbox the same name with [] at the end so that it will be posted as an array, for example:
<input type="checkbox" name="thisone[]" value='004'>
<input type="checkbox" name="thisone[]" value='005'>
<input type="checkbox" name="thisone[]" value='112'>


Then loop through this array in your next script using a regular for loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top