axiomx11 Posted February 5, 2007 Share Posted February 5, 2007 The answer looks like this: <input name="<? echo $row["id"] ?>[param]" type="radio" value="None" /> I am trying to think of a clever way to do this. I have a database of monkeys, listed by name, and I would like to record their meal preferences. Most like bannanas, but some like bananas with salt, and some like grapefruits (with our without salt). To build my form I start with a SQL statement "SELECT * FROM monkeys" And then add a row to my form to record their preference monkey01 ()banana ()grapefruit ()salt ()no salt ()ketchup monkey02 ()banana ()grapefruit ()salt ()no salt ()ketchup monkey03 ()banana ()grapefruit ()salt ()no salt ()ketchup monkey04 ()banana ()grapefruit ()salt ()no salt ()ketchup (I forgot to mention that some of them like ketchup. Those are radio buttons BTW) Since I don't know how many monkeys are going to be in the form, when I process it, I must do my SQL statement again, and check for GET values for every monkey_id in the database. I have gotten it to send the banana/grapefruit preference by using the monkey_id as the varable name for that form value, but I am not sure how I am going to record the salt/no salt/ketchup preference. I can combine the monkey_id with something to create unique variables, but I wouldn't know how many there are, so I couldn't properly check for them. Is there some way I can pass this as an array? Link to comment https://forums.phpfreaks.com/topic/37156-solved-mysql-a-form-and-a-lot-of-radio-buttons/ Share on other sites More sharing options...
janroald Posted February 5, 2007 Share Posted February 5, 2007 There are two ways to do this : when u make your form, you can also make an array containing the id's of the monkeys in the list, corresponding to the db id of the monkey. This array you can serialize, (http://www.php.net/serialize) and pass along in a hidden input field with a name of your choosing. When u submit your form you can unserialize the data from your hidden field and voila you got your array of id's to check for. The second way is to make a hidden field for every monkey row like this monkey01 <input type="hidden" name="monkey_ids[]" value="01" /> monkey02 <input type="hidden" name="monkey_ids[]" value="02" /> $_POST[monkey_ids] (if u use post method) will now contain an array with the monkey ids. Link to comment https://forums.phpfreaks.com/topic/37156-solved-mysql-a-form-and-a-lot-of-radio-buttons/#findComment-177438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.