Old 10-04-2005   #1 (permalink)
Registered User
 
Join Date: Oct 2005
Posts: 1

Adding pagination

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
esiason14 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 10-04-2005   #2 (permalink)
code anyone?
 
scrowler's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Posts: 590

Send a message via MSN to scrowler Send a message via Skype™ to scrowler
should be the same principle:

[start] = page_num * page_length
[numtoshow] = page_length

LIMIT [start], [numtoshow]
__________________
BioRUST Tutorials - the birthplace
scrowler is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 10-04-2005   #3 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
I see you are using MySQL,so adding pagination wont be a problem,trus do a search to all the old post in this category and u`ll find what u want.
In case u need a pagination for texfile database,its all there,just search.
good luck
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 10-04-2005   #4 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,073
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Well, here's the code that I use... its quite simple, but it does the job...

PHP Code:
$ENTRIES_PER_PAGE 15;
$firstEntryIndex = ($pageno 1) * $ENTRIES_PER_PAGE;
$lastEntryIndex  = ($pageno $ENTRIES_PER_PAGE) - 1;
$lastEntryIndex  min($countOfEntries 1$lastEntryIndex);

  if (
ceil($countOfEntries $ENTRIES_PER_PAGE) > 1)
  {
    
$maintable .= "    <p align=right><i>Go To Page:";

    for (
$ii 0$ii ceil($countOfEntries $ENTRIES_PER_PAGE); $ii++)
    {
      if (
$pageno == ($ii 1))
      {
        
$maintable .= "    " . ($ii 1) . "\n";
      }
      else
      {
        
$maintable .= "    <a class='affiliates' href='/webindex/browse/" $catid "/" $order "/" $sorting "/" . ($ii 1) . "/'><u>" . ($ii 1) . "</u></a>\n";
      }
    }
  }
  
$maintable .= "</p>\n";

echo 
$maintable
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed with PHP: Pagination in a tut system nitr0x HTML / PHP / ASP / JS 3 05-24-2005 05:30 PM
Adding brush problem, need help.. ArticBlue Adobe Photoshop 1 03-25-2005 07:45 PM
Adding text to a textarea using javascript BlodoPKNZ HTML / PHP / ASP / JS 11 03-11-2005 12:40 PM
Pagination tutorial here! ParaSnake HTML / PHP / ASP / JS 0 10-16-2004 04:28 AM
Adding Styles Bleekster Adobe Photoshop 5 10-13-2004 08:41 PM


All times are GMT +1. The time now is 05:27 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT