jbrill Posted December 4, 2007 Share Posted December 4, 2007 hey guys, this is probably a very stupid question, but need some help... i have a list of check boxes in a form, each with a different value ( the value is the id of the colors in the colors table) as you can see here : <? $colorsquery = mysql_query("SELECT * FROM colors"); while ($colors = mysql_fetch_array($colorsquery)) { echo '<input type="checkbox" name="color" value="' . $colors['id'] . '"">' . $colors['name'] . '<br />'; } ?> my question is, how do i echo the $_POST so that it takes all the checked off boxes and puts values like so: 1;2;3;4;5 Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/ Share on other sites More sharing options...
mr_mind Posted December 4, 2007 Share Posted December 4, 2007 This stores them in a variable and then echos the color <?php if($_POST['submit']) { $array = $_POST['color']; foreach($array as $color) { print '<span style="color: ' . $color . ';"> ' . $color . ' </span><br />'; } } else { $colorsquery = mysql_query("SELECT * FROM colors"); print '<form action=' . $_SERVER['PHP_SELF'] . ' method=post>'; while($colorsarray = mysql_fetch_array($colorsquery)) { echo '<input type=checkbox name=color[] value=' . $colorsarray['id'] . ' />' . $colorsarray['name'] . '<br />'; } print '<input name=submit type=submit value=Submit />'; print '</form>'; } ?> Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406337 Share on other sites More sharing options...
mr_mind Posted December 4, 2007 Share Posted December 4, 2007 Then if you want to separate them with a semicolon try: $explode = explode(",", $color); $implode = implode(";", $explode); Which would set it up into an array separated by semicolons. Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406345 Share on other sites More sharing options...
jbrill Posted December 4, 2007 Author Share Posted December 4, 2007 i tried the explode/implode method with no luck, here is my code: // combine the colors and seperate with semi colons $array = $_POST['color']; foreach($array as $color) { } is there any other way to do it, or can you show me the proper way? thank you Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406351 Share on other sites More sharing options...
jbrill Posted December 4, 2007 Author Share Posted December 4, 2007 also, this information will be stored in a row in a data base so in the end, it needs to be one variable holding all the color id's Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406353 Share on other sites More sharing options...
jbrill Posted December 4, 2007 Author Share Posted December 4, 2007 ? anyone Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406372 Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 <?php $colors = implode(';',$_POST['color']); ?> Link to comment https://forums.phpfreaks.com/topic/80169-solved-posting-multiple-vars-and-separating-them-by-semi-colon/#findComment-406377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.