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

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>

Archived

This topic is now archived and is closed to further replies.

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