Hey all, I've been trying to figure out how to add pagination to the following script. Should be relatively easy, but I'm having a heck of a time.
First of all here is my script...
PHP Code:
<?php
$public=1;
require_once("config.php");
require_once($DOC_ROOT . "/lib/header.php");
// select weeks first, and make links
$query = "select week from playerstats group by week";
$result = mysql_query($query);
while($week = mysql_fetch_array($result)){
// build html for links
$links_html .= "<a href='weeklyleaders.php?week=" . $week["week"] . "'>" . $week["week"] . ""."</a> | ";
}
// print links here
print "<table align=\"center\">";
print "<tr>";
print "<td>Select a Week: </td>";
echo "<td align=\"center\">$links_html</td>";
echo "</tr> </table>";
// now select for this specific week
$week = $_GET["week"];
if(empty($week))
$week = 1;
print "<h2 align=\"center\">Week " . $week . ": Leaders</h2>";
print "<h2 align=\"center\">Running Backs</h2>";
$query = "SELECT lname, fname, rush_att, rush_yd, rush_td, rec_att, rec_yd, rec_td, playerstats.player_id,
players.nflteam_id, nflteam_abbv
FROM playerstats, players, nflteams
WHERE playerstats.player_id = players.player_id
AND nflteams.nflteam_id = players.nflteam_id
AND nflteam_abbv = nflteams.nflteam_abbv
AND week = '" . $week . "'
ORDER by rush_yd DESC
LIMIT 20";
$result = mysql_query($query);
//checking output
$num_results = mysql_num_rows($result) or die(mysql_error());
if ($num_results == 0)
{
echo "No Results Found";
}
else
{
?>
<table align="center" width="85%">
<tr>
<th><b><u>Player</u></b></th>
<th><b><u>Team</b></u></th>
<th><b><u>Rush Att</b></u></th>
<th><b><u>Rush YD</b></u></th>
<th><b><u>Rush TD</b></u></th>
<th><b><u>Receptions</b></u></th>
<th><b><u>Rec YD</b></u></th>
<th><b><u>Rec TD</b></u></th>
</tr>
<?php
$i = 0;
while($row = MySQL_fetch_array($result)) {
$lname = $row['lname'];
$fname = $row['fname'];
$rush_yd = $row['rush_yd'];
$rush_att = $row['rush_att'];
$rush_td = $row['rush_td'];
$rec_att = $row['rec_att'];
$rec_yd = $row['rec_yd'];
$rec_td = $row['rec_td'];
$week = $row['week'];
$nflteam_id = $row['nflteam_id'];
$player_id = $row['player_id'];
$abbv = $row['nflteam_abbv'];
if($i++ % 2) {
$bgcolor = "silver";
} else {
$bgcolor = "white";
}
echo " <tr bgcolor=\"$bgcolor\"><td><a href='players.php?player_id=" . $player_id . "'> ".$fname."
".$lname."</td>";
echo "<td>".$abbv."</td>";
echo "<td align=\"center\">".$rush_att."</td>";
echo "<td align=\"center\">".$rush_yd."</td>";
echo "<td align=\"center\">".$rush_td."</td>";
echo "<td align=\"center\">".$rec_att."</td>";
echo "<td align=\"center\">".$rec_yd."</td>";
echo "<td align=\"center\">".$rec_td."</td>";
}
}
?>
</table>
Since I'm joining three tables...I'm having hard time following some of the tutorials...If anyone can help me out, it would be greatly appreciated