Jump to content

Help with "WHILE LOOP"


pacchiee

Recommended Posts

Hi,

 

I have been using a WHILE LOOP to fetch data from a table and display it as a list. In each loop, I want to select an entry in another table based on the data fetched in the loop. Tried to fetch data from a table within the loop and am not able to do this.

 

For Example

 

This works:

<?php

$result = mysql_query("SELECT * FROM table1 WHERE id='variable1'");

$row = mysql_num_rows( $result );

while($row = mysql_fetch_array( $result )) {

$fetchdata = $row['somecolumn'];

if($fetchdata == XX){echo "result1";}else{echo "result2";}

} ?>

 

But this is not working:

<?php

$result = mysql_query("SELECT * FROM table1 WHERE id='variable1'");

$row = mysql_num_rows( $result );

while($row = mysql_fetch_array( $result )) {

$fetchdata = $row['somecolumn'];

$result1 = mysql_query("SELECT * FROM table2 WHERE id='$fetchdata'");

$row1 = mysql_num_rows( $result1 );

$fetchdata1 = $row1['somecolumn'];

if($fetchdata1 != XXX){echo "result1";}else{echo "result2";}

} ?>

 

Please help.

Link to comment
https://forums.phpfreaks.com/topic/100928-help-with-while-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.