Jump to content

How to display x amount of tables rows depending on y amount of info in a query


Lucky2710

Recommended Posts

Heres what i got...

function printLB1 (){
$result = mysql_query("SELECT * FROM leaderboards ORDER BY CollegeFootballPoints DESC");
while ($row = mysql_fetch_object($result)) {
    $leaderboard[] =  $row->Username;
$leaderboardPoints[] = $row->CollegeFootballPoints;
}
$num = mysql_num_rows($reault);

//I know from here to ...................  needs to be in a var or echo or something.

  <tr>
    <td>1.</td> //This will auto increment too like i++ but i cna do that myself!
    <td>echo $leaderboard;</td>
    <td>echo $leaderboardPoints;</td>
  </tr>

//Here.........................................................

}

 

I need to pull a table row per user. But i want to somehow do it once in a function and then ill echo the function into a table after the php stuff is done.

 

Like i want to pull every a table row per user in the function. then display the function below that way i don't have to write a whole extra query and table row per person.

 

If you understand please help if not please let me know where i can explain more.

 

Thanks

Link to comment
Share on other sites

Heres what i did!

 

function printLB1($week){
$weeknum = 'Week'.$week;

$result = mysql_query("SELECT * FROM CollegeFootballWeeklyLeaderboards ORDER BY $weeknum DESC");
while ($row = mysql_fetch_object($result)) {
    $username[] =  $row->Username;
$leaderboardPoints[] = $row->$weeknum;
}
$num = mysql_num_rows($result);

for($i=0; $i< $num; $i++) {

echo '  <tr>
    <td>'.$i.'.</td> 
    <td>'.$username[$i].'</td>
    <td>'.$leaderboardPoints[$i].'</td>
  </tr> ';
}


}

?>

<table width="68%" border="1" cellspacing="0" cellpadding="5">
  <tr>
    <td width="14%"><strong>Position</strong></td>
    <td width="51%"><strong>User</strong></td>
    <td width="35%"><strong>Points</strong></td>
    </tr>
    <? printLB1(1); ?>
</table>

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.