vistar86 Posted April 26, 2010 Share Posted April 26, 2010 Hi please be tame with me i'm new to php So now i'll tell you the problem. This has multiple selection checkboxes form, so person could check up to 9 checkboxes in color section, and different amounts of checkboxes in each sections. don't know if "(list" is the way to be going as theres many more _POST to be added after the "||" i would like it for each checkbox checked as $val the same $v should be put at end of each $val checked. hope you understand? THE FORM <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <body onload="document.forms['Form1'].reset()"> <form action="phonefinder.php" name="Form1" method=POST> <table> <tr class="pfinderhead"><td colspan="3"><b>Screen Size:</b></td></tr> <tr><td style="width:35%;">128x160: <input type="checkbox" value="first" name="screen[]"></td><td style="width:30%;">176x220: <input type="checkbox" value="second" name="screen[]"></td><td style="width:35%;">240x320: <input type="checkbox" value="third" name="screen[]"></td></tr><tr><td style="width:35%;">Larger: <input type="checkbox" value="fourth" name="screen[]"></td><td style="width:35%;">Any: <input type="checkbox" value="fifth" name="screen[]"></td><td style="width:30%;">Touch: <input type="checkbox" value="sixth" name="screen[]"></td></tr> </table> <table> <tr class="pfinderhead"><td colspan="3"><b>Colour:</b></td></tr> <tr><td style="width:35%;">Black: <input type="checkbox" value="black" name="colour[]"></td><td style="width:30%;">Blue: <input type="checkbox" value="blue" name="colour[]"></td><td style="width:35%;">Gold: <input type="checkbox" value="gold" name="colour[]"></td></tr><tr><td style="width:35%;">Grey: <input type="checkbox" value="grey" name="colour[]"></td><td style="width:30%;">Pink: <input type="checkbox" value="pink" name="colour[]"></td><td style="width:35%;">Red: <input type="checkbox" value="red" name="colour[]"></td></tr><tr><td style="width:35%;">Silver: <input type="checkbox" value="silver" name="colour[]"></td><td style="width:30%;">White: <input type="checkbox" value="white" name="colour[]"></td><td style="width:35%;">Any/Other: <input type="checkbox" value="ANY" name="colour[]"></td></tr> </table> <input type="submit"/> </form> </body> THE SCRIPT $screen=$_POST['screen']; $color=$_POST['colour']; while ( (list ($key,$val) = @each ($screen)) || (list ($k,$v) = @each ($color)) ) { ///Output should be first $val in list followed by $v; then second $val in list followed by SAME $v } So say if i checked in the Screen: a,b,c,d. Then checked in color: 1,2,3,6,7,9. would like it to output: a,1,2,3,6,7,9 b,1,2,3,6,7,9 c,1,2,3,6,7,9 d,1,2,3,6,7,9 NOT like a,b,c,d,1,2,3,6,7,9 which it does now. thanks in advance hope someone can help me Link to comment https://forums.phpfreaks.com/topic/199771-while-list-sorting/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 This SHOULD work: $screen= empty($_POST['screen']) ? array() : $_POST['screen']; //Use ternary operators to default to a blank array if nothing was submitted $color= emtpy($_POST['colour']) ? array() : $_POST['screen']; //Use ternary operators to default to a blank array if nothing was submitted foreach($screen as $v) //Loop through screen values { echo $v; //echo a/b/c etc. foreach($color as $c) //Loop through color values { echo ', ' . $c; } echo "<br />"; //Line break } Link to comment https://forums.phpfreaks.com/topic/199771-while-list-sorting/#findComment-1048556 Share on other sites More sharing options...
vistar86 Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks for your input but the result of this is: a,b,c,d b,b,c,d c,b,c,d d,b,c,d the colours are not showing, only screen, even though i selected colors also. but i can see that its getting there Link to comment https://forums.phpfreaks.com/topic/199771-while-list-sorting/#findComment-1048574 Share on other sites More sharing options...
vistar86 Posted April 26, 2010 Author Share Posted April 26, 2010 No you were right only missed one small thing : $color= emtpy($_POST['colour']) ? array() : $_POST['screen']; thanks changed the screen to colour erm, what about all the other sections to come? screen is main section then want to add to end of screen > colours > type > style > features etc, i think i may be able to do it now thanks to you, but any input will be great Link to comment https://forums.phpfreaks.com/topic/199771-while-list-sorting/#findComment-1048582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.