Jump to content

pagination help


steviez

Recommended Posts

Hi,

 

I have created some pagination code for my script and need some help to iron out a bug. When there are no more results to show i want the next button to not show but no matter what i do it always shows enableing the user to navigate through blank pages.

 

Here is my code:

 

<?php

// Limit Results On Page
$max_results = 9;
$total_results = @mysql_result(mysql_query("SELECT COUNT(*) as Num FROM uploads WHERE album_id = '".$_GET['galleryID']."'"),0);
$total_pages = ceil($total_results / $max_results);

if(!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) 
{
  $startrow = 0;
}else{
  $startrow = (int)$_GET['startrow'];
}

if($total_results > $max_results)
{
$next_link = $site_url . '/albums.php?galleryID='.$_GET['galleryID'].'&startrow='.($startrow+$max_results).'';
$next = "<a href=\"".$next_link."\" title=\"Next\" /><img src=\"".$site_url."/templates/css/images/next.gif\" alt=\"Next\" width=\"16\" height=\"16\" style=\"border:none;\" /></a>";
}

if($startrow !== 0)
{
$previous_link = $site_url . '/albums.php?galleryID='.$_GET['galleryID'].'&startrow='.($startrow-$max_results).'';
$prev = "<a href=\"".$previous_link."\" title=\"Previous\" /><img src=\"".$site_url."/templates/css/images/previous.gif\" alt=\"Previous\" width=\"16\" height=\"16\" style=\"border:none;\" /></a>";
}

?>

 

 

Any help would be awsome :)

Link to comment
Share on other sites

Hi Steve,

 

<code>

$total_results = @mysql_result(mysql_query("SELECT COUNT(*) as Num FROM uploads WHERE album_id = '".$_GET['galleryID']."'"),0);

</code>

 

It will result suppse 50 records

 

<code>if($total_results > $max_results)</code> will always return 9

 

hence the if condition will always be true. you need to keep LIMIT in your query to fetch the current total records.

 

<code>

$total_results = @mysql_result(mysql_query("SELECT COUNT(*) as Num FROM uploads WHERE album_id = '".$_GET['galleryID']."'") LIMIT $start_limit,$max_results,0);

 

on every page $start_limit will update.

 

Regards

</code>

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.