Canman2005 Posted November 23, 2007 Share Posted November 23, 2007 hi all i have a php form which contains a query, the query is used to generate a series of tick boxes $sql = "SELECT * FROM extras ORDER BY id ASC"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { ?> <input name="extra" type="checkbox" value="<?php print $row['title']; ?>" /> <?php } this creates a series of tick boxes. is it possible to somehow group the id numbers of the ones that are ticked, so it would create a variable containing all the id numbers, for example $extrasticked = '12 ,34 ,56 ,76'; could this be done? thanks ed Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 $sql = "SELECT * FROM extras GROUP BY id ORDER BY id ASC"; Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted November 23, 2007 Author Share Posted November 23, 2007 i mean how can i grab all the id numbers of the tick boxes selected when the form is submitted, so i can store the id numbers of the ticked boxes in a field within the database Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 some modification to your code to achieve that $sql = "SELECT * FROM extras ORDER BY id ASC"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { ?> <input name="extra[]" type="checkbox" value="<?php print $row['title']; ?>" /> <?php } when the form is posted $extrasticked = ""; if (isset($_POST['extra')) { $extrasticked = implode(",",$_POST['extra']); } echo $extrasticked; hope it helpful notice that in the first html form I have added "[]" to the checkbox Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Make the input name an array: <input name="extra[]" type="checkbox" value="<?php print $row['title']; ?>" /> Now, when submitted, you will have a variable named $_POST['extra'] or $_GET['extra'] depending on your form method. For an array, I'd recommend POSTing the data. At the receiving end, do: <?php if ( !empty($_POST['extra']) ) { echo "<pre>"; print_r($_POST['extra']); echo "</pre>"; } You will see a printout of all the values that were ticked. You can take it from there. PhREEEk Quote Link to comment 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.