Re: result set in php pagination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have tested the script with echo() which shows that the correct $numrows is returned and then
$totalpages = ceil($numrows / $rowsperpage);

Everything is correct on the first page of results. The pagination links are displayed correctly but when clicked on the resulting page is empty.

For some reason I do not understand the result set does not carry through to the succeeding links in the pagination sequence.

Thanks,
Joe
On 23 Jan 2010, at 19:16, Edward Brookhouse wrote:

Isn't there a matching select later that sets up the number of pages?

I start with:

$offset = ($pageNum - 1) * $rowsPerPage;
db_connect_ecelerity(DBUSER, DBUSERPW);
$query1 = "select * FROM `bouncelog` ORDER BY `insert_date` DESC LIMIT $offset, $rowsPerPage";
$numresults=mysql_query($query1);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query1) or die('Error, lame query failed');


Then a bunch of display the data stuff but ending with:

$query   = "SELECT COUNT(insert_date) AS numrows FROM bouncelog";
$result  = mysql_query($query) or die('Error, query lamefailed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

if ($pageNum > 1)
{
   $page = $pageNum - 1;
   $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
   $first = ' [First Page] '; // nor 'first page' link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
   $last = ' [Last Page] '; // nor 'last page' link
}

echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;

echo "</table>";
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
       ?>




-----Original Message-----
From: Joe Keenan [mailto:heresiarch@xxxxxxxxxxxxxxx]
Sent: Saturday, January 23, 2010 1:16 PM
To: php-db@xxxxxxxxxxxxx
Subject:  result set in php pagination

I am using php and mysql.

The problem which I am hoping someone can help me with concerns
pagination of the result set of a search of a single table.

I got the pagination script I am using from a Sitepoint tutorial and
it works just as it should for this query

"SELECT article_id, category_name, author_name, title,
article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM
articles where article_id > 0 ORDER BY magazine_date DESC LIMIT
$offset, $rowsperpage"

The result set is return over many pages with no problem at all.

When it comes to this next query however it delivers the first page of
results and sets up the linked pages but those are empty.

"SELECT article_id, author_name, category_name, title,
article_caption, date_format(magazine_date, '%M, %Y') as newdate FROM
articles WHERE author_name = '$author_name' ORDER BY magazine_date ASC
LIMIT $offset, $rowsperpage"

I assume the problem must have to do with '$author_name' which is
passed to the search script as '$author_name = $_POST["author_name"];'
from a php form.

Is there something I should be doing to ensure that the result set
from the query persists though the change in pagination from the first
page of results to the second page.

In both cases the search scripts are includes in other php pages.

I think I need to understand how the result set is carried through or
reacquired in the pagination process.

Sorry if this is phrased very clumsily.

Thank you,

Joe Keenan

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux