RE: [PHP] Branching blunder

2004-08-05 Thread Alex Hogan
 
[snip]
 Because $answers = 5; is the last check of $answers unless 
 the else statement is invoked. Try this...
[/snip]

That was it.., I don't know why I didn't see that.


Thanks Jay.


alex
*
The contents of this e-mail and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom it is addressed. The 
views stated herein do not necessarily represent the view of the company. If you are 
not the intended recipient of this e-mail you may not copy, forward, disclose, or 
otherwise use it or any part of it in any form whatsoever. If you have received this 
e-mail in error please e-mail the sender. 
*

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Branching blunder

2004-08-05 Thread Ford, Mike [LSS]
On 05 August 2004 15:15, Jay Blanchard wrote:

 [snip]
 if($ans_three[$qzid] === 'None of the above' || $ans_three[$qzid] ===
'All of the above'){ if($ans_four[$qzid] === 'None of the above'
   || $ans_four[$qzid] === 'All of the above'){
 $answers  =   rand(6,8); 
 
}
$answers   =   5;
 }
 else{
$answers   =   rand(1,4);
 }
 
 However when I run it, it checks everything correctly until it has
 answer three and four having 'All of the above' and 'None of
 the above',
 then it branches to $answer = 5, only.  Why?
 [/snip]
 
 Because $answers = 5; is the last check of $answers unless the else
 statement is invoked. Try this...
 
 if($ans_three[$qzid] === 'None of the above' || $ans_three[$qzid] ===
'All of the above'){ if($ans_four[$qzid] === 'None of the above'
   || $ans_four[$qzid] === 'All of the above'){
$answers   =   rand(6,8); } elseif($ans_four[$qzid] !== 'None of
the
 above' || $ans_four[$qzid] !== 'All of the above'){

Ehhhrrrmmm -- that elseif () condition is always going to be true:
logically, it's got to be not equal to one or other of the values.

From a quick glance at the code, I'd say just a straight else would do the
job here, thus:

  if ($ans_three[$qzid] === 'None of the above'
  || $ans_three[$qzid] === 'All of the above')
  {
if ($ans_four[$qzid] === 'None of the above'
|| $ans_four[$qzid] === 'All of the above')
{
  $answers = rand(6,8);
}
else
{
  $answers = 5;
}
  }
  else
  {
$answers = rand(1,4);
  }

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php