Jump to content

while list sorting


vistar86

Recommended Posts

Hi please be tame with me i'm new to php :confused:

 

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 :D

Link to comment
https://forums.phpfreaks.com/topic/199771-while-list-sorting/
Share on other sites

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

No you were right only missed one small thing :

 

$color= emtpy($_POST['colour']) ? array() : $_POST['screen'];

 

:D thanks changed the screen to colour :P

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.