Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two conditions in a while loop 1

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
0
0
CA
Hail,

Can you put two conditions in a while loop? Reason I want to know is I have two arrays I want to loop through, only stopping the loop when BOTH are eof.

Something like:

$queryH="SELECT * FROM Goals";
$resultH=mysql_query($queryH);
$queryA="SELECT * FROM Assists";
$resultA=mysql_query($queryA);
while($rowH=mysql_fetch_array($resultH) OR $rowA=mysql_fetch_array($resultA))
{
*** code here would check if either is eof, if not then it would print in a table, $queryH in 1st column, $queryA in column 2
}

 
That while() only has one condition. It's a complex condition, but only one.

Since you're using the operator OR instead of ||, it should work. It's not necessarily very readable, though.



Want the best answers? Ask the best questions! TANSTAAFL!
 
It doesn't work, I get an error on this line:

while($rowH=mysql_fetch_array($resultH) OR $rowA=mysql_fetch_array($resultA))


The error is (shows twice as if each statement is wrong???):

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\wamp\ on line 71
 
Then your SQL is wrong.

mysql_query() will only return a MySQL result resource when it can successfully run a SELECT query.

See section 1.5 of faq434-2999



Want the best answers? Ask the best questions! TANSTAAFL!
 
You're right, I changed the query and it worked, thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top