Jump to content

Pagination Error


aussiefly

Recommended Posts

ok this is my first go at php pagination and its working.....sort of :)

 

Here is the guts of my pagination and query code (ive still got things to change like the count rather than just selecting all rows etc).

 


// check to see if page number is set and if not set it.
if(isset($_GET[’pagenum’]))
{
$pagenum = $_GET[’pagenum’];
}
else
{
$pagenum = 1;
}

//Here we count the number of results 
//Edit $data to be your query 
$data = mysql_query("SELECT * FROM `transactions` where `user_id` = $_SESSION[userid]") or die(mysql_error()); 
$rows_count = mysql_num_rows($data); 

//This is the number of results displayed per page 
$page_rows = 6; 

//This tells us the page number of our last page 
$last = ceil($rows_count/$page_rows); 

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

//This sets the range to display in our query 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

// query transactions database for user history

$trans_query = "SELECT * FROM `transactions` where `user_id` = $_SESSION[userid] $max";
$trans_result = mysql_query($trans_query);
php?>

<h1> User Account History </h1><table cellpadding="10" border="1" rules="rows" frame="void">
<tr>
<td>Trans #</td><td>Date</td><td>Liberty #</td><td>Amount</td><td>Type</td><td>Status</td></tr>

<?php
while ($row = mysql_fetch_assoc($trans_result))
{     
php?>
 <tr>
 <td><?php echo $row['trans_id']; php?></td>
     <td><?php echo $row['date']; php?></td>
 <td><?php echo $row['liberty_acc']; php?></td>
 <td><?php echo $row['amount']; php?></td>
 <td><?php echo $row['type']; php?></td>
 <td><?php echo $row['status']; php?></td>
 </tr>


<?php
} // end loop
php?>
</table>
<?PHP
// This shows the user what page they are on, and the total number of pages
echo " --Page $pagenum of $last-- <p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='history1.php?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='history1.php?pagenum=$previous'> <-Previous</a> ";
} 

//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='history1.php?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='history1.php?pagenum=$last'>Last ->></a> ";
} 
php?>

 

The problem is that it seems to display the results fine...but when i go to click next page etc...nothing happens and it just sits there.

 

The problem is clearly somewhere in the updating of the $max variable which is actually the limit....it doesnt seem to be updating from what i can see...and i just cant see what to fix.

 

Any ideas

 

p.s im really going to have to donate to the site after all the time you guys have been putting into helping me learn some scripting.

 

Cheers :)

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.