Re: Do two lists in a while statement
| From: | Jim Lucas | Date: | Sun, 22 Apr 2007 00:55:28 +0000 |
| Subject: | Re: Do two lists in a while statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253456@lists.php.net to get a copy of this message | ||
Richard Kurth wrote:
On 4/21/07, Richard Kurth <richardkurth@centurytel.net> wrote:Ok, not sure about where you are pulling/representing some of your data, but here is what I came up with in-place of your code. foreach( $fields AS $field ){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 $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(,$possible) = each($possiblefields)&&list(,$possibleview) = each($possiblefieldsdiscription)){$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++; }
echo " <TR>\n"; echo " <TD><SELECT NAME=fieldorder[]>\n";for( $i=0; $i<count($possiblefields); $i++ ) { $possible = (isset($possiblefields[$i]) ? $possiblefields[$i] : 'NOT_SET'); $possibleview = (isset($possiblefieldsdiscription[$i]) ? $possiblefieldsdiscription[$i] : 'NOT_SET'); if ( isset($fieldorder[$fieldnumber]) && $fieldorder[$fieldnumber] == $possible ) { $sel = 'selected="selected"'; } else { $sel = ''; } echo "<OPTION value=\"{$possible}\" {$sel}>{$possibleview}</OPTION>\n"; }
echo " </SELECT></TD>\n";
echo " <TD>{$field}</TD>\n";
echo " </TR>\n";
}
Give it a try and let us know
Jim Lucas