Pagination won't carry results past page 2.


Posted on 16th Feb 2014 07:03 pm by admin

Hi all,

I've worked out my pagination script and its paginating fine until I click next from page 2 at which point it stops displaying results. I know its something really simple, but can't see what lol.

Here is my code, anyone able to help?

Code: $connection = mysql_connect($hostname, $username, $password);
#
if (!$connection) {
#
die("A connection to the server could not be established");
#
}
#
/*Select Database */
#
mysql_select_db($database) or die("Database could not be selected!");
#

#
/*set variables*/
#
if (isset($_GET['MerchantType']) && isset($_GET['County'])){
#
$MerchantType = $_GET["MerchantType"];
#
$County = $_GET["County"];
#
echo $County . " " . $MerchantType;
#
}
#

#
/* Set current, prev and next page */
#
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
#
$next = $page + 1;
#
$prev = $page - 1;
#

#
/* Max results per page */
#
$max_results = 5;
#

#
if (!$connection) {
#
die("A connection to the server could not be established");
#
}
#
/* Select Database */
#
mysql_select_db($database) or die("Database could not be selected!");
#

#

#
/* Figre out how many items there are in your DB */
#
$q = "SELECT * FROM $tablename WHERE County = '$County' AND MerchantType = '$MerchantType'";
#
$result = mysql_query($q) or die(mysql_error());
#
$total_results_pages = mysql_num_rows($result);
#

#
/* Must know where to begin grabbing the results from the DB */
#
$limitvalue = $page * $max_results - ($max_results);
#

#
// query
#
$q = "SELECT * FROM $tablename WHERE County = '$County' AND MerchantType = '$MerchantType' LIMIT $limitvalue, $max_results";
#
$result = mysql_query($q) or die(mysql_error());
#
$total_results = mysql_num_rows($result);
#

#
$total_pages = ceil($total_results_pages / $max_results);
#

#

#

#
echo '$total_results_pages = '.$total_results_pages;
#
echo '
';
#
echo '$total_results = '.$total_results;
#
echo '
';
#
echo '$max_results = '.$max_results;
#
echo '
';
#
echo '$total_pages = '.$total_pages;
#
echo '
';
#
echo '$page = '.$page;
#
echo '
';
#
echo '$next = '.$next;
#
echo '
';
#
echo '$prev = '.$prev;
#
echo '
';
#
echo '$limitvalue = '.$limitvalue;
#
echo '<hr>';
#

#

#
while ($row_details = mysql_fetch_array($result))
#
{
#
echo '
<table class="results" border="1" bordercolor="#1d9346">
<style="background-color:#FFFFFF" width="800" cellpadding="3" cellspacing="3">
<tr>
<td width="200" align="left" rowspan="7"><img src = "images/Test.png" /></td>
</tr>
<tr>
<td width="573" height="27" align="left">Name: '.$row_details['MerchantName'].'</td>
</tr>
<tr>
<td height="27" align="left">Address 1: '.$row_details['AddressLine1'].'</td>
</tr>
<tr>
<td height="27" align="left">Address 2: '.$row_details['AddressLine2'].'</td>
</tr>
<tr>
<td height="27" align="left">Telephone: '.$row_details['Telephone'].'</td>
</tr>
<tr>
<td height="27" align="left">Website: '.$row_details['Website'].'</td>
</tr>
<tr>
<td height="27" align="left">Description: '.$row_details['Description'].'</td>
</tr>
</table><br />';
#
}
#

#
// show next
#
if ($page == 1 && $page < $total_pages)
#
{
#
echo '<a href="?MerchantType='.$MerchantType.'&County='.$County.'&page='.$next.'">Next</a>';
#
}
#

#
// shoe prev & next
#
if ($page > 1 && $page < $total_pages)
#
{
# // prev link
#
echo '<a href="?MerchantType='.$MerchantType.'&County='.$County.'$page='.$prev.'">Previous</a> |';
// next link
#
echo '<a href="?MerchantType='.$MerchantType.'&County='.$County.'$page='.$next.'">Next</a> ';
#

#
}
#

#
// show prev
#
if ($page > 1 && $page == $total_pages)
#
{
#
echo '<a href="?MerchantType='.$MerchantType.'&County='.$County.'&page='.$prev.'">Previous</a>';
#
}

Sam

No comments posted yet

Your Answer:

Login to answer
262 Like 21 Dislike
Previous forums Next forums
Other forums

Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system

sql error
I have been looking at this code for 20mins and can't work out what I am doing wrong. There is somet

When file included, REMOTE_ADDR is server's?
I have an index file that handles my site, basically index.php?page=ip will activate "require('

Open link with largest int string first
I have the following links i would like to open either all at once or one-by-one. How would i procee

Adding Different Numbers From MySQL
Basically I have a mysql database with a couple prices as the following:

9.99
9.99
9.99

Why is my row count 0?
Here's the MySQL query i'm running. It basically pulls data from 2 tables based on some data passed.

How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g

How can I get my program to read a larger array ??
Hi:

I have this program that reads from an array to do calculations. The array are just t

IMAGE - SERVER SIDE scripting help...
How to receive pixel data of an image and buid a bitmap file on the server using the HTTP POST metho

Count on multidimensional array
Hi, i got an array as below:

Array
(
=> Array
(

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash