YourNameHere Posted November 4, 2009 Share Posted November 4, 2009 I have several DB queries that I know should be returning results and aren't. I have a feeling it has to do with the several while loops that should be outputting the data. One more issue is that when I echo the num_rows they are all 0 except the first one. BTW I checked that all variables were being populated and they were. Here is my code: $sql1 = "SELECT * FROM player1 where player = '$username'"; $sql2 = "SELECT * FROM player2 where player = '$username'"; $sql3 = "SELECT * FROM player3 where player = '$username'"; $sql4 = "SELECT * FROM player4 where player = '$username'"; $sql5 = "SELECT * FROM player5 where player = '$username'"; $sql6 = "SELECT * FROM player6 where player = '$username'"; $result1 = mysql_query($sql1); $result2 = mysql_query($sql2); $result3 = mysql_query($sql3); $result4 = mysql_query($sql4); $result5 = mysql_query($sql5); $result6 = mysql_query($sql6); $num1 = mysql_num_rows($result1); $num2 = mysql_num_rows($result2); $num3 = mysql_num_rows($result3); $num4 = mysql_num_rows($result4); $num5 = mysql_num_rows($result5); $num6 = mysql_num_rows($result6); while ($b < $num1){ $game=mysql_result($result1,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } while ($b < $num2){ $game=mysql_result($result2,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } while ($b < $num3){ $game=mysql_result($result3,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } while ($b < $num4){ $game=mysql_result($result4,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } while ($b < $num5){ $game=mysql_result($result5,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } while ($b < $num6){ $game=mysql_result($result6,$b,chatId); $g="SELECT * from chats where name = '$game'"; $gResult= mysql_query($g); $info=mysql_fetch_assoc($gResult); echo " <tr> <td>" . $info['realName'] . "</td> <td>" . $info['dm'] . "</td> </tr> "; $b++; } I have tried changing the variable $b to something else in each loop but that didnt work either. Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/ Share on other sites More sharing options...
ILMV Posted November 4, 2009 Share Posted November 4, 2009 Why not just try: while($num1); ? Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-950875 Share on other sites More sharing options...
GingerRobot Posted November 4, 2009 Share Posted November 4, 2009 That looks like you've overcomplicated the issue. Why are you executing the same query for various users. What is it that you're actually trying to do? Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-950893 Share on other sites More sharing options...
YourNameHere Posted November 4, 2009 Author Share Posted November 4, 2009 what I am trying to do is.... I have a chat room, that can accept 6 people + a moderator. That moderator has to invite those 6 people. so I have 6 sql tables player1 - player6. This function is going to iterate through each table and find each occurrence of the this persons name and display it on a page. This is an invite. Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-951044 Share on other sites More sharing options...
YourNameHere Posted November 4, 2009 Author Share Posted November 4, 2009 Is there a better way to write the select query possibally using the AND keyword or (the lesser understood) JOIN? Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-951373 Share on other sites More sharing options...
YourNameHere Posted November 9, 2009 Author Share Posted November 9, 2009 Any help available? Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-954012 Share on other sites More sharing options...
YourNameHere Posted November 9, 2009 Author Share Posted November 9, 2009 figured it out Link to comment https://forums.phpfreaks.com/topic/180255-solved-multiple-while-loops/#findComment-954025 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.