123guy Posted March 3, 2013 Share Posted March 3, 2013 so I am forming some checkboxes in a php loop ( i am not showing the loop, but it is in a loop). I need to be able to have multiple check box rows with multiple values. I am doing a customer tracking system. I need each check box to hold the Customer First, Last, and Memberid. How can I do this using php? I would prefer not to have to loop through an array, so if there is a way not to do that, it would be great! <input type="radio" name="CheckboxGroup" value="yes" id="CheckboxGroup1_0<?php echo $id; ?>"><input name="first" type="hidden" value="<?php echo $first; ?>"><input name="last" type="hidden" value="<?php echo $last; ?>"><input name="member" type="hidden" value="<?php echo $id; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/275193-checkbox-groups/ Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 If you already have the data in a database, which it appears you do, since you are outputting those values to the page, then just assign the id to the checkbox and then on the next page, pull those values from the database for the checkboxes that are checked. So say you have multiple groups: <input type="checkbox" name="response[]" value="<?php echo $id;?>"> Option 1 <br /> // Next loop <input type="checkbox" name="response[]" value="<?php echo $id;?>"> Option 2 Then you can loop through the values in PHP. foreach ($_POST['response'] as $theID) { } Quote Link to comment https://forums.phpfreaks.com/topic/275193-checkbox-groups/#findComment-1416328 Share on other sites More sharing options...
123guy Posted March 4, 2013 Author Share Posted March 4, 2013 Would it be the same way if I decided to use a radio button instead? Or would I not use the for each? Quote Link to comment https://forums.phpfreaks.com/topic/275193-checkbox-groups/#findComment-1416330 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 Yes, but you'll need to use similar radio names to make the select functionally work as they should <input type="radio" name="radiobutton[0]" value="a"><br> <input type="radio" name="radiobutton[0]" value="b"><br> <input type="radio" name="radiobutton[1]" value="a"><br> <input type="radio" name="radiobutton[1]" value="b"><br> Quote Link to comment https://forums.phpfreaks.com/topic/275193-checkbox-groups/#findComment-1416334 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.