Lucky2710 Posted August 11, 2010 Share Posted August 11, 2010 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 https://forums.phpfreaks.com/topic/210393-how-to-display-x-amount-of-tables-rows-depending-on-y-amount-of-info-in-a-query/ Share on other sites More sharing options...
Lucky2710 Posted August 11, 2010 Author Share Posted August 11, 2010 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 https://forums.phpfreaks.com/topic/210393-how-to-display-x-amount-of-tables-rows-depending-on-y-amount-of-info-in-a-query/#findComment-1097891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.