Wouldn't you need 
if ( $num_results == 0 ) not
if ( $num_results = 0 )

if you do the latter, it will allways be true, because you're setting the
var...

easy mistake to make!


check out comparisons in the manual for more info.

Justin French



on 12/06/02 11:19 PM, Roberts, Mark ([EMAIL PROTECTED]) wrote:

> Being relatively new to php, I discovered the following after about 2 hours
> of debugging last night and was wondering why???
> 
> I had the following code:
> 
> if ( $num_results = 0 )
> {
> echo "no records found";
> }
> else
> {
> for ($i=0; $i < $num_results; $i++)
> {
> display record set
> }
> }
> 
> As a result, the for loop never executed, no matter how many records were
> returned in the record set. I placed echo statements though out to determine
> why the for loop was not being executed. I put an echo statement just before
> the for to make sure the else condition was being met.
> 
> Finally, I just copy/pasted (literally) the for loop to just before the 'if'
> statement. Much to my surprise...the for loop now works perfectly. (Except,
> of course, if there are no records returned).
> 
> The duduction...for loops will not work inside else statements. The
> question...why?
> 
> I think I can work around this with some different coding, but why should I
> have to? I have done this same thing in java, perl and other languages...
> 
> Mark Roberts
> Sr. Systems Analyst
> LanApps/Web Development
> The Williams Information Services Corporation
> 918-573-1706
> [EMAIL PROTECTED]
> 
> 
> 


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

Reply via email to