Jump to content

Recommended Posts

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");
?>

 

Link to comment
https://forums.phpfreaks.com/topic/95910-mysql-loops-only-displaying-one-user/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.