gobbles Posted February 13, 2008 Share Posted February 13, 2008 Hey All, I got a bit of a problem thats giving me a major headache. I have a form which generates checkboxes from a database, so there isnt a set number of them ... they are generated by the following: while ($listing_row = mysql_fetch_array($listing_results)) { extract($listing_row); echo "<input type=\"checkbox\" name=\"checkbox\" value=\"".$description."\" id=\"list".$id."\" ><label for=\"list".$id."\"> " .$description . "</label><font color=\"#FF0000\"> - ".$date_uploaded."</font><br />\r"; } I want the next script to take each of the checked boxes and assign them to a variable so that i can recall them at a later stage. For example ... if there was 150 checkboxes and only 2 were checked, then $checked1 would equal the description of the first checked box, $checked2 would equal the description of the second checked box, and so on. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/90930-dynamic-checkbox/ Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 Change the 'name' to checkbox[] $_POST['checkbox'] will then be an array. Quote Link to comment https://forums.phpfreaks.com/topic/90930-dynamic-checkbox/#findComment-466023 Share on other sites More sharing options...
gobbles Posted February 13, 2008 Author Share Posted February 13, 2008 Ok, no problem .. How about assigning variable names to the checked values? Quote Link to comment https://forums.phpfreaks.com/topic/90930-dynamic-checkbox/#findComment-466043 Share on other sites More sharing options...
laffin Posted February 13, 2008 Share Posted February 13, 2008 U already are doing that $descriprion is returned if the checkbox is checked. if checkbox is left unchecked, nothing is returned checkboxes, only return values when they are checked. so if u have 150 checkboxes, and 2 get checked $_POST['checkbox'] wud return an array of 2 items (not 150) with the $description of those 2 checked as a value Quote Link to comment https://forums.phpfreaks.com/topic/90930-dynamic-checkbox/#findComment-466129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.