Lamez Posted March 13, 2008 Share Posted March 13, 2008 My loop is only displaying one user, how do I get it to display all records? The information is coming from three different tables. The loop is coming out of userpoints. here is the code: <?php include ("../../style/include/session.php"); include ("../../style/include/cons/head_2.php"); print '<div class="box">'; if($session->logged_in){ include ("../../style/include/checkuser.php"); ?> <table width="100%" border="0"> <tr> <td> </td> <td><strong>Username</strong></td> <td><strong>Store # </strong></td> <td><strong>2nd Round </strong></td> <td><strong>Sweet 16 </strong></td> <td><strong>Elite 8</strong></td> <td><strong>Final 4 </strong></td> <td><strong>Finals</strong></td> <td><strong>Championship</strong></td> <td><strong>Tie Breaker </strong></td> <td><strong>Total</strong></td> </tr> <?php $q = "SELECT * FROM `userpoints` ORDER BY `total`"; $r = mysql_query($q); while ($rs=mysql_fetch_array($r)){ $q = "SELECT * FROM `users` WHERE `username`='".$rs['username']."'"; $r = mysql_query($q); $re = mysql_fetch_array($r); $q = "SELECT * FROM `champ` WHERE `username`='".$rs['username']."'"; $r = mysql_query($q); $tb = mysql_fetch_array($r); ?> <tr> <td> </td> <td><?php echo $rs['username']; ?></td> <td><?php echo $re['store']; ?></td> <td><?php echo $rs['rnd1']; ?></td> <td><?php echo $rs['rnd2']; ?></td> <td><?php echo $rs['rnd3']; ?></td> <td><?php echo $rs['rnd4']; ?></td> <td><?php echo $rs['rnd5']; ?></td> <td><?php echo $rs['champ']; ?></td> <td><?php echo $tb['tb']; ?></td> <td><?php echo $rs['total']; ?></td> <? } ?> </tr> </table> <?php }else{ include ("../../style/include/cons/member.php"); } print '</div>'; include ("../../style/include/cons/foot.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/ Share on other sites More sharing options...
Lamez Posted March 13, 2008 Author Share Posted March 13, 2008 I did not think this would be hard for the experts out there. Any Idea? Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/#findComment-491043 Share on other sites More sharing options...
roxki Posted March 13, 2008 Share Posted March 13, 2008 You're sure you've the same users in all 3 MySQL tabels? Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/#findComment-491105 Share on other sites More sharing options...
Lamez Posted March 13, 2008 Author Share Posted March 13, 2008 yep. I looked and made sure the information match to the user. But I am only get one user to output. I do not know why. Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/#findComment-491163 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2008 Share Posted March 13, 2008 You're using the same variable "$r" to store the results of the different mysql_query() calls, so the while loop is being screwed up. Use different variables: <?php $q = "SELECT * FROM `userpoints` ORDER BY `total`"; $r = mysql_query($q); while ($rs=mysql_fetch_array($r)){ $q = "SELECT * FROM `users` WHERE `username`='".$rs['username']."'"; $r1 = mysql_query($q); $re = mysql_fetch_array($r1); $q = "SELECT * FROM `champ` WHERE `username`='".$rs['username']."'"; $r2 = mysql_query($q); $tb = mysql_fetch_array($r2); ?> <tr> <td> </td> <td><?php echo $rs['username']; ?></td> <td><?php echo $re['store']; ?></td> <td><?php echo $rs['rnd1']; ?></td> <td><?php echo $rs['rnd2']; ?></td> <td><?php echo $rs['rnd3']; ?></td> <td><?php echo $rs['rnd4']; ?></td> <td><?php echo $rs['rnd5']; ?></td> <td><?php echo $rs['champ']; ?></td> <td><?php echo $tb['tb']; ?></td> <td><?php echo $rs['total']; ?></td> <?php } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/#findComment-491193 Share on other sites More sharing options...
Lamez Posted March 14, 2008 Author Share Posted March 14, 2008 Wow that fixed it, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/#findComment-491932 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.