pacchiee Posted April 13, 2008 Share Posted April 13, 2008 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 More sharing options...
raku Posted April 13, 2008 Share Posted April 13, 2008 You need an additional while loop for result1.. for example: <?php while($row1 = mysql_fetch_array($result1)) { $fetchdata1 = $row1['somecolumn']; } ?> Link to comment https://forums.phpfreaks.com/topic/100928-help-with-while-loop/#findComment-516146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.