By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,039 Members | 1,831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,039 IT Pros & Developers. It's quick & easy.

Create x amount of checkboxes based on data in table

P: 2
Hi,

Firstly, i have 2 tables that i need to populate. 'recipe' and 'recipeequipment'. I need to get a list of equipment from the 'equipment' table and their ids and display this to the user so they can choose what equipment they like(possibly more than 1).

My question is how do i create x amount of checkboxes with the equipment from the table. alongside this i will need a textbox so that the user can input how many of each equipment they want.

This will ofcourse need to be put into the database so will need unique ids in the form so i can get the values required.

Does anyone have any suggestions of how to accomplish this?

Thanks.
Nov 24 '11 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
I assume you'll do it in a loop and use the unique id as part of the form control's name.
Nov 25 '11 #2

P: 13
1) make sure your recipeequipment table has an auto increment primary key. By this you are having a unique key / id for every record automaticly.

2) SELECT all records from recipeequipment` where the recipe id is the one you need into one array.

3) use sizeof($arrayname) or count($arrayname) on the resultset to get the amount.

This way you have all the data you need alongside with the number of records and their respective unique ids (inside every record in the array)

Step 3 could be left off if you want to display the recipeequipment line by line .. you would just use some foreach() loop iterating over the array you got in 2)

2)
Nov 26 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.