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 Quote Link to comment 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>'; } ?> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
jbrill Posted December 4, 2007 Author Share Posted December 4, 2007 ? anyone Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 <?php $colors = implode(';',$_POST['color']); ?> 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.