RE: [PHP] global variable declaration
| From: | Jay Blanchard | Date: | Wed, 08 Feb 2006 15:00:29 +0000 |
| Subject: | RE: [PHP] global variable declaration | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-230094@lists.php.net to get a copy of this message | ||
[snip]
for($j=0;$j<5;$j++):
$result=mysql_query("select * from user where SponsorID='$id[$j]'
");
endfor;
in above code when i print mysql_num_rows($result) inside for loop
its output is 5.when i print outside the for loop its o/p is 0.I searched
weberdev.com website and declared $result as global.but same output 0.i
want $result variable to be available outsibe the forloop and all other
part of my code.i am looking forward suggestions from ur side.
[/snip]
You are running the query 5 times, to the mysql_num_rows($result) value will
be different each time through the for loop. Try this and you'll see....
for($j=0;$j<5;$j++):
$result=mysql_query("select * from user where SponsorID='$id[$j]'
");
echo $j . " " . mysql_num_rows($result) . "<br
/>\n";
endfor;
The output will be
0 some number of rows
1 some number of rows
2 some number of rows
3 some number of rows
4 some number of rows
My bet is that the last row will have 0 rows