Re: [PHP-DB] result set in php pagination

[email protected] (Joe Keenan)
Newsgroups php.db
Message-ID <[email protected]>
Thanks very much Bastien. I haven't the faintest idea why but that  
simple change in the code sorted all of this. The pagination links now  
follow through with the complete result set of my query.

I will now have to read around this to discover why the change works.

And thanks very much to everyone who took the trouble to reply to my  
cry for help. It is all very much appreciated.

Joe.
On 23 Jan 2010, at 21:32, Phpster wrote:

> If you change the $_POST to &_REQUEST in this piece of code
>
>> $author_name = $_POST["author_name"];'
>
> To make it
>
>> $author_name = $_REQUEST["author_name"];'
>
> Should fix that issue
>
> Bastien
>
> Sent from my iPod
>
> On Jan 23, 2010, at 4:26 PM, Joe Keenan <[email protected]>  
> wrote:
>
>> This is all that results from the included script on the 2nd  
>> display page:
>> <div id="c-col">
>>
>> <div align="center">
>> <h3>Articles by </h3>
>> <h4>(There are 0 articles in the database.)</h4>
>> </div>
>> <p></p>
>> <div align="center">
>> <a href='results_1.php?currentpage=2&author_name='><em>Next</em></ 
>> a>  <a href='results_1.php?currentpage=0&author_name='>>></a> </div>
>> </div>
>>
>> Given that the where clause in the original query is "WHERE  
>> author_name = '$author_name' " I cannot see how passing the  
>> author_name in the pagination url will help.
>>
>> Should I somehow pass $author name which was originally picked up  
>> from a form as
>>
>> '$author_name =  '$author_name = $_POST["author_name"];'
>>
>> Clearly I am at a loss here. Could anyone suggest anything in the  
>> PHP Manual, or any tutorial or anything at all on the web about  
>> sustaining a result set through pagination links when the SELECT  
>> clause of the query is modified by a WHERE clause containing a  
>> variable.
>>
>> As it stands I am unable to construct a search engine query to  
>> cover the matter.
>>
>> Thanks
>> Joe.
>>
>>
>> On 23 Jan 2010, at 20:45, lists-php wrote:
>>
>>> You haven't actually indicated what's on the 2nd display page, but I
>>> suspect that it's just the select statement, with the (url passed)
>>> pagination substituted in. [one can pass the results in an array,
>>> but it's unlikely that you're doing that, so your subsequent pages
>>> simply re-issue the query] if you're doing that, then you'll also
>>> have code that picks up the pagination parameters from the url.
>>> you'll need to add coding to pick up the "author" too, otherwise the
>>> 2nd page won't pick it up and use it.
>>>
>>> also, in our link example in an earlier message:
>>>
>>> http://...results_1.php?currentpage=2&&author_name=Editorial
>>>
>>> you show two ampersands before "author_name". there should only be
>>> one. also, if your author's name includes a space, you'll need to
>>> deal with that.
>>>
>>>
>>> - Rick
>>>
>>>
>>>
>>> ------------ Original Message ------------
>>>> Date: Saturday, January 23, 2010 08:23:23 PM +0000
>>>> From: Joe Keenan <[email protected]>
>>>> To: Edward Brookhouse <[email protected]>
>>>> Cc: [email protected]
>>>> Subject: Re: [PHP-DB] result set in php pagination
>>>>
>>>> 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:[email protected]]
>>>>> Sent: Saturday, January 23, 2010 1:16 PM
>>>>> To: [email protected]
>>>>> Subject: [PHP-DB] 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
>>>>>
>>>>>
>>>>>
>>>
>>> ------------ End Original Message ------------
>>>
>>>
>>
>>
>> -- 
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.