Jump to content

Pagination needed for existing script


webready

Recommended Posts

Hello All!

 

I was hoping one of you phpFreaks could help me out :)

 

I have the following code that produces links from a database. Certain sets of results have over 3000 links. I can currently set the amount of links to display per page but that's it.

 

I would like to be able to truncate the links to all the pages using pagination.

 

Any help would be greatly appreciated!

 

Here is the code:

 

<?php 

echo "Results<br><HR WIDTH=100% SIZE=1><br>";
mysql_connect("mysite.com", "mysite_mysite", "mysitepassword") or die(mysql_error()); 
mysql_select_db("user_database") or die(mysql_error()); 


if (isset($_GET['pagenum']))
{
  $pagenum = $_GET['pagenum'];
} else
{
  $pagenum = 1;
} 

$rpg = $pagenum;
$data = mysql_query("SELECT * FROM mydb WHERE mfg='golf'") or die(mysql_error()); 
$rows = mysql_num_rows($data); 
$page_rows = 80; 

$last = ceil($rows/$page_rows); 

if ($pagenum < 1)
  {
   $pagenum = 1;
  } 
elseif ($pagenum > $last) 
  {
   $pagenum = $last;
  } 

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 
$data_p = mysql_query("SELECT * FROM mydb WHERE mfg='golf' $max") or die(mysql_error()); 

while($info = mysql_fetch_array( $data_p )) 
  { 
   $page=$info['link'];
echo "<a href='$page' class='blue1'>". $info['title'] . "</a><br>"; 
  } 
   echo "<p>";

if ($pagenum > $last) 
  {$pagenum=1;} 
else
{ 
  echo "<HR WIDTH=100% SIZE=1><br>";
  $pagenum = 1;
    while ($pagenum <= $last)
    {
       $next = $pagenum;
       echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class='g5'>$pagenum</a> ";
       $pagenum = $pagenum+1;
      
    }
  Echo "<br><br>Page $rpg of $last <br>";
}

?>

 

Simple insertion of pagination would be GREAT! Thanks guys....

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.