Jump to content

[SOLVED] mySQL Display Help


fLaVV

Recommended Posts

What I am trying to do is display members that are in a certain group from my phpbb (group is clan members) and display them in my roster.php file. My script is working fine and displaying the information that I want it to...but for some reason it isn't looping. It is only displaying the first result. Below is the code, sadly this is the only way I know how to do this, so if you guys know of a better way...im open for ideas.

 


<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><strong>Username:</strong></td>
    <td align="center"><strong>Email:</strong></td>
    <td align="center"><strong>Rank:</strong></td>
  </tr>

<?
$connection = mysql_connect("localhost","username","password");
mysql_select_db("database");

$urfcheck = mysql_query("SELECT * FROM phpbb_user_group WHERE group_id = '12'");
while ($row = mysql_fetch_array($urfcheck)){
$user = $row['user_id'];
}

$getrank = mysql_query("SELECT * FROM phpbb_xdata_data WHERE user_id = '$user'");
while ($row = mysql_fetch_array($getrank)){
$rank = $row['xdata_value'];
}

$grabinfo = mysql_query("SELECT username FROM phpbb_users WHERE user_id = '$user'");
while ($row = mysql_fetch_array($grabinfo)){
$username = $row['username'];

  echo "<tr>
    <td align=center>$username</td>
    <td align=center><a href=forums/profile.php?mode=viewprofile&u=$user>Click Here</a></td>
    <td align=center>$rank</td>
  </tr>
</table>";
}
mysql_close($connection);
?>

Link to comment
Share on other sites

Your brackets were in the wrong place.  Indenting your code always helps with this :) See below

 

*edit*  I did a bad job of indenting, and had to fix the closing table. 

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><strong>Username:</strong></td>
    <td align="center"><strong>Email:</strong></td>
    <td align="center"><strong>Rank:</strong></td>
  </tr>

<?
$connection = mysql_connect("localhost","username","password");
mysql_select_db("database");

$urfcheck = mysql_query("SELECT * FROM phpbb_user_group WHERE group_id = '12'");

while ($row = mysql_fetch_array($urfcheck)){
  $user = $row['user_id'];

  $getrank = mysql_query("SELECT * FROM phpbb_xdata_data WHERE user_id = '$user'");
  while ($row = mysql_fetch_array($getrank)){
    $rank = $row['xdata_value'];
  }

  $grabinfo = mysql_query("SELECT username FROM phpbb_users WHERE user_id = '$user'");
  while ($row = mysql_fetch_array($grabinfo)){
    $username = $row['username'];
  } 

  echo "<tr>
    <td align=center>$username</td>
    <td align=center><a href=forums/profile.php?mode=viewprofile&u=$user>Click Here</a></td>
    <td align=center>$rank</td>
  </tr>";
}
mysql_close($connection);
?>
</table>

Link to comment
Share on other sites

As a further response.  Yes there is a better way to do it, however it's been to long since I've done Joins in MySQL to rememeber how to pull all the data in one query...  Something like the following may work

 

SELECT phpbb_user_group.user_id, phpbb_xdata_data.xdata_value, phpbb_users.username FROM phpbb_user_group, phpbb_xdata_data, phpbb_users WHERE phpbb_user_group.group_id = 12' and phpbb_user_group.user_id = phpbb_xdata_data.user_id and phpbb_user_group.user_id = phpbb_users.user_id

 

I don't know if that's perfect, and don't ask me to explain it to ya... here's some quick info on Joins

http://www.tizag.com/mysqlTutorial/mysqljoins.php

 

Link to comment
Share on other sites

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.