Jump to content

PHP pagination problem


justin7410

Recommended Posts

Hey guys,

 

i am trying to create some pagination within my page to allow a user to go through my entire catalog or data from my database.

 

i have everything working correctly ( kinda ) , but for some reason when i then click on a link to get me around the pages, i get some problems.

 

VARIABLES TO CREATE PAGINATION

$per_page = 25;
$page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
$start = ($page - 1 ) * $per_page;

CONDITIONAL TO SEE WHERE THE USER IS AND WHAT TYPE OF INFO THEY WANT

if(in_array($person_type,$all_links) === true) {  // genre matches array of genres
$query = "SELECT * FROM  `content` WHERE  `person_type` LIKE  '%$type%' AND `is_type`=0 AND is_rating
AND isdb_votes >10000
ORDER BY isdb_join_date DESC
LIMIT $start , $per_page ";   <--- this is where variables are being presented to track the position.

//echo $query; 
       } 
   if (in_array($letter, $all_links) === true){
$query = "SELECT * FROM  `content` WHERE  `imdb_title` LIKE  '$letter%' AND `is_type`=0 AND is_rating
AND isdb_votes >10000
ORDER BY isdb_join_date DESC
LIMIT $start , $per_page "; <--- this is where variables are being presented to track the position.
//echo $query;    }    

 if (in_array($year, $all_links) === true) { $query = "SELECT * FROM  `content` WHERE  `imdb_release_date` LIKE  '%$year%' AND `is_type`=0 AND is_rating
AND isdb_votes >10000
ORDER BY isdb_join_date DESC
LIMIT $start , $per_page "; <--- this is where variables are being presented to track the position.
//echo  $query; }

THIS THEN QUERIES THE QUERY FROM WHICHEVER CONDITIONAL IS PASSED 

$links = mysql_query($query);

DIV WHERE PAGINATION IS

<div>

<?
$pages = ceil(mysql_result($links, 0) / $per_page);


if ($pages >= 1) {
for ($x = 1; $x<=$pages; $x++ ) {
if (isset($_GET['genre']) === true) { 
echo '<a href = "browse.php?type='.$type.'&page='.$x.'">'.$x.' ';
}
else if (isset($_GET['letter']) === true) {
echo '<a href = "browse.php?type='.$type.'&letter='.$letter.'&page='.$x.'">'.$x.' ';  
}
else if (isset($_GET['year']) === true) {
echo '<a href = "browse.php?type='.$type.'&year='.$year.'&page='.$x.'">'.$x.' ';
}
}
}
?>

</div>

THE ISSUE:

 

i get the links to show up and they all direct me to the correct query and connection to the Database.

 

the first couple pages will work correctly, and there are no issues with the pagination.

 

if you see above there is a variables called $pages = which spits out the number of pages total needed depending on how many items i want to be outputted. ( i.e 25 ). 

 

so one category would have 100 pages , one would have 300, and some even with say 10 pages.

 

Now when i click on say page 10 of 100 that is being echoed the query fails. not only does the query fail , but the amount of pages numbers being outputted changes for the same directory.

 

so category 1 with 100 pages then becomes category 1 with 67 pages.

 

this makes no sense to me as to why this is happening. i also cant seem to understand also why i keep getting an error of 

 

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 16 in/home/justin/public_html/include/pagination.php on line 4

 

 

 

to my understanding the query is no longer returning true , and now there are zero rows returning, yet if there was no more data to be given , why is there a page number being outputted in the first place ?

 

any suggestions to this problem ?

 

any help would be greatly appreciated.

Edited by justin7410
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.