Hello,
I have set up a script to add paging to a search results page. Which on
the first page works fine. The recordset calculates how many pages there should be
depending on the number of results returned from my search and how many
records I have set it to display per page. All great so far, HOWEVER.....

When you click the next link to see the next 10 results on the next page, it
just dumps the search details and goes to a blank page. When you click Previous or First it just goes back to a blank record. If you less recoreds then the number set to display, and click on next - it brings up all the records which exist, so you find yourself with the counter then showing 300+ records all in one go, ignoring the number of records which have been set to display!

I need to find a way of using this paging system in conjunction with the
search results, so if for example I search for "yellow" and I get 18
matching results with the first 10 being displayed on the first page, & I
then click next, I would like to see the last 8 results on the next page,
with the option to click 'prev' and see the previous 10 again. What actually
happens is that it shows me the first 10 matching results and says
displaying page 1 of 2, I click the 'next' link and it suddenly says showing
page 2 of 32 and starts listing all the records from the database starting
at record number 11 !

I suspect that when you click on the paging links, it is the refreshing of the page which loses the search results. But even making the fields 'sticky'in the search results fields is not making any difference to the paging links.

This is the code for the Record Paging Links

<table width="508" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="112">&nbsp;</td>
                <td width="127" class="maintext">Total Properties = &nbsp;<?php echo $totalRows_rs_agentlists ?></td>
                <td width="269" align="right" class="maintext"><a href="<?php printf("%s?pageNum_rs_agentlists=%d%s", $currentPage, 0, $queryString_rs_agentlists); ?>">First Page</a> |<a href="<?php printf("%s?pageNum_rs_agentlists=%d%s", $currentPage, min($totalPages_rs_agentlists, $pageNum_rs_agentlists + 1), $queryString_rs_agentlists); ?>"> Next Page</a> |&nbsp;<a href="<?php printf("%s?pageNum_rs_agentlists=%d%s", $currentPage, max(0, $pageNum_rs_agentlists - 1), $queryString_rs_agentlists); ?>">Previous Page</a> |&nbsp;<a href="<?php printf("%s?pageNum_rs_agentlists=%d%s", $currentPage, $totalPages_rs_agentlists, $queryString_rs_agentlists); ?>">Last Page</a></td>
              </tr>
            </table>

The code upfront for setting the recordset display etc is:

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rs_agentlists = 10;
$pageNum_rs_agentlists = 0;
if (isset($_GET['pageNum_rs_agentlists'])) {
  $pageNum_rs_agentlists = $_GET['pageNum_rs_agentlists'];
}

Please let me know if you need to code with the query in and the form?

Any help would be really really appreciated.

Many thanks liz

Recommended Answers

All 6 Replies

DO you know about php datagrid428 (its free). YOu can create forms where you can add/edit/delete/print/export with ease and paging option. Also you can connect php with any database well known.

I would recommend to not waste time in writing code. go for it.

Warning: free version is with some bugs and they have stopped supporting users of free version. But basic functionality still works.

Before using datagrid428, when I was paging myself. I used to use cookie to store search criteria and page numbers.

Hi Thanks for getting back to me. I'll take a look.

For the cookies - would that be better than passing the form variables via $_SESSION?

Also where would you put this code within the main php page?

Many thanks

you may use session variable but take care naming variable, name them accoring to page name.
I think its better to store paging, searching info in clients computer using cookies, rather than using session variable.

Hi can anyone help me with how and where the coding would go to take the field value and store it in a session/cookie against the 'next' page link etc? I'm really stuck I have to say.

Many thanks

Hi. I've solved this. I just changed all the Form attributes to $_GET instead of $_POST and changed the form method to 'get' and any $_POST in the sql query. This now seems to work fine.

Many thanks for all the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.