Re: Do two lists in a while statement
| From: | Tijnema ! | Date: | Sat, 21 Apr 2007 20:35:42 +0000 |
| Subject: | Re: Do two lists in a while statement | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253446@lists.php.net to get a copy of this message | ||
On 4/21/07, Richard Kurth <richardkurth@centurytel.net> wrote:
-----Original Message----- From: Tijnema ! [mailto:tijnema@gmail.com] Sent: Saturday, April 21, 2007 1:13 PM To: Richard Kurth Cc: php-general@lists.php.net Subject: Re: [PHP] Do two lists in a while statement On 4/21/07, Richard Kurth <richardkurth@centurytel.net> wrote: On 4/21/07, Richard Kurth <richardkurth@centurytel.net> wrote:Quite strange, I personally never work with list/each, but with foreach. But well,that is personal preference. I updated below code, so that it does the second list inside the while loop. It should work the same. (as long as $possiblefieldsdiscription and $possiblefields have same amount of keys) Tijnema $fieldnumber = 0;On 4/21/07, Richard Kurth <richardkurth@centurytel.net> wrote:Yes, isn't that what you wanted? Normaly a while checks also if it was TRUE. now it checks if both are TRUE.. If you only require one of both to be TRUE, use || instead of &&. I am trying to fill in the drop down box in the script below but it is not working it is only giving me the $possibleview data but not the $possible data Hmm strange, i don't see any real error, so to test if it's a problem with the while loop, you could assign the backward order. So the code would look like the one below. Please test it, and see if you still get the same problem, or if you get $possible now instead of $possibleview. Tijnema $fieldnumber = 0;How can I do something like this in the same while statement. This does not work while (list(,$possible) = each($possiblefields) list(,$possibleview) = each($possiblefieldsdiscription)){ }What about using && ? while (list(,$possible) = each($possiblefields) && list(,$possibleview) = each($possiblefieldsdiscription)){ } Doesn't && mean if both variables are TRUE.while (list(,$field) = each($fields)){ echo " <TR>\n"; echo " <TD><SELECT NAME=fieldorder[]>\n"; reset($possiblefields); reset($possiblefieldsdiscription); $anyselected = '';while (list(,$possibleview) =each($possiblefieldsdiscription) && list(,$possible) = each($possiblefields)){$selected = @(($fieldorder[$fieldnumber] == $possible) ?'SELECTED' : '');if ($fieldnumber >= count($fieldorder) && !$anyselected){ $selected = 'SELECTED'; } echo "<OPTION value=\"$possible\"$selected>$possibleview</OPTION>\n";} echo " </SELECT></TD>\n"; echo " <TD>$field</TD>\n"; echo " </TR>\n"; $fieldnumber++; }It now passes the $possible fields but not the $possibleview so it is picking up the last list but not the first I also tried it with || and it does the same thing
while (list(,$field) = each($fields)){
echo " <TR>\n";
echo " <TD><SELECT NAME=fieldorder[]>\n";
reset($possiblefields);
reset($possiblefieldsdiscription);
$anyselected = '';
while (list(,$possibleview) = each($possiblefieldsdiscription)){
list(,$possible) = each($possiblefields);
$selected = @(($fieldorder[$fieldnumber] == $possible) ?'SELECTED' : '');
if ($fieldnumber >= count($fieldorder) && !$anyselected){
$selected = 'SELECTED';
}
echo "<OPTION value=\"$possible\"
$selected>$possibleview</OPTION>\n";
}
echo " </SELECT></TD>\n";
echo " <TD>$field</TD>\n";
echo " </TR>\n";
$fieldnumber++;
}