Re: Question: Simpler loop

From: Date: Fri, 22 Oct 2004 15:08:20 +0000
Subject: Re: Question: Simpler loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-200088@lists.php.net to get a copy of this message
Stuart Felenstein wrote:
I have rows of input fields Each row contains 3 fields. The user must fill out the entire row (all 3 fields) for things to work right. I want to generate an error in case they have only filled in 1 or 2 of the boxes. Thinking I might use something like this: foreach($skills as $key => $skill)
    {
    if ($skill != '' && $skys[$key] = '' &&
$slus[$key] = '')
    {
}else if{
    if ($skill = '' && $skys[$key] != '' &&
$slus[$key] = '')
BEWARE - single equal sign assigns right operand to the left one, you need doulble, which compares and returns either false or true.
}else{
    if ($skill = '' && $skys[$key] = '' && $slus[$key]
!= '') ..... above only takes into account that 1 of that 3 has been filled in. I would need another set to take into account if 2 of the 3 have been filled in. Is there a simpler way / shorter way to check conditions to do this ?
foreach($skills as $key => $skill) { $filled_in = 0; if($skill != '') $filled_in++; if($skys[$key] != '') $filled_in++; if($slus[$key] != '') $filled_in++; if($filled_in < 2) ERROR(); }

« previous php.general (#200088) next »