zavin Posted September 10, 2011 Share Posted September 10, 2011 Why does this code only display 1 result? If I PRINT $row3 all results diplay, but the variable will only give 1 result. It would be easier for me to just PRINT row3, but I have 13 rows with different loops. $sql = "SELECT * FROM $city WHERE SG_Name='$sg GROUP BY ID'"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { $ID="{$row[3]}"; } print "<tr border='1'> <td>".$Source_ID."</td> </tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/246859-problem-with-while-loop/ Share on other sites More sharing options...
mikesta707 Posted September 10, 2011 Share Posted September 10, 2011 You overwrite the value of $ID in each iteration of the loop, so at the end $ID consists of the last value returned from your query Quote Link to comment https://forums.phpfreaks.com/topic/246859-problem-with-while-loop/#findComment-1267797 Share on other sites More sharing options...
zavin Posted September 10, 2011 Author Share Posted September 10, 2011 Makes perfect since. Didn't think about that, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/246859-problem-with-while-loop/#findComment-1267798 Share on other sites More sharing options...
mikesta707 Posted September 10, 2011 Share Posted September 10, 2011 No problem. Thats what i'm here for. marking your topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/246859-problem-with-while-loop/#findComment-1267815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.