Need help with checkbox form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Need help with checkbox form

Post by Stryks »

I need to create a form with a series of checkboxes, one for each entry in a table in a mySQL database.

I'm wondering if anyone can give me some idea of the best way to convert a returned list of values into a list of checkboxes which will add more checkboxes automatically if needed.

Also, once the values have been updated by the checkboxes, what is the best way to write them back?

Any help or ideas of where to start would be great. Thanks.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

I have a page with a list of quesitons that each have a radio button for yes,no, or n/a. I keep track of it by having a no_string and a na_string which each of which is simply a list of numbers, if question seven was answered na, then the na_string gets a 7. so then I check to see if each nymber is in either string. if its not, then its assumed yes. Does that help?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

you'll need a form, a while loop, and to create the form into an array so when multiples check boxes are selected, each retaining variable for each checked box is transfered.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

Thanks for the feedback, but I'm still not sure I understand fully.

Starting with first things first ... writing the boxes to the form. The number of checkboxes will depend on how many records there are that match the users ID, so the number will be different for everyone.

With this in mind, how should I go about naming the checkboxes? I had thought like 'item[1] item[2]' etc. But that doesnt appear to work at all.

How should I name them, and how can I keep track of the corellation of checkboxes to database options?

Thanks
joespenceley
Forum Newbie
Posts: 3
Joined: Tue Mar 23, 2004 9:34 pm

Post by joespenceley »

working on a very similar form myself and i hope to complete it tonight. if i get the damn thing working i will let you know how.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

well what exactly kind of info do u wish to display (with a checkbox beside it)

is that info in the db? also, what do u plan to do with taht info when checked? delete it, edit it? send it to a different page?

let me know
Post Reply