Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pagination but same page/form 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Is there an easy way to fill an HTML table with say 30 records, and on submission to itself refill the table with the next batch etc,etc. I can work out the values of number of rows in the table, and navigation, its how to put this in the select query statement. Regards
 
Thanks, I did look at that FAQ but does that not generate pages? Is there any way to refill the table on the same page with ascending/descending values stored in session variables. Regards
 
Thanks both. Can you explain this part to me please:

//this is the logic for the "next" link display
print '<td width="50%" align="center">';
if ($limit_start + $records_per_page < $record_count)
{
print '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($current_page + 1) . '">next</a>';

Are there other pages being generated?

My problem is I have page thats basically a query by reference, using checkboxes the user can dynamically design a WHERE statement which gets put into the select query on submission back to itelf to fill an HTML table. I tried similar code to the FAQ, but for some reason my WHERE part of the statement gets lost, and page 2 (next) shows unfiltered data, ie all records.

The code ending used was:

if ($pagenumber == 1) {
echo " First Previous ";
} else {
//echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=1&where=$where'>First</a> ";
$prevpage = $pagenumber-1;
//echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$prevpage&where=$where'>Previous</a> ";
}

echo " ( Page $pagenumber of $lastpage ) ";

if ($pagenumber == $lastpage) {
echo " Next Last ";
} else {
$nextpage = $pagenumber+1;
//echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$nextpage&where=$where'>Next</a> ";
//echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$lastpage&where=$where'>Last</a> ";
}


Thanks Jpadie, I will also look into Ajax.
 
The code segment you pointed out supplies a link back to the same script. Since the script takes information on the URL to know which page of data to display, that snippet outputs all the necessary information on the URL to tell the script to fetch either the next or the previous page of data.


As far as "losing" your where-clause, what have you done to preserve it betweenn successive runs of the script? My original code preserves everthing through data in the URLs used in links.



Want the best answers? Ask the best questions! TANSTAAFL!
 
ajax will only help you avoid page refreshes. for the underlying logic of paging then sleipnir's script in the FAQ section is the place to be. there is, of course, no reason why you cannot deploy his solution with ajax as the latter is simply a method of interacting with the server "behind the scenes".
 
Each time the page comes back it first checks the status of checkboxes (used in the WHERE statement), It then creates or recreates the WHERE statement. depending if its the first or multiple time the page has come back. Everything works fine if I forget pagination, it's just I was worried what would happen when the HTML table grew too long for the page. Is it permitted to play with the Limit 0,10, Limit 11,20 etc values, or out of the question. Thanks
 
Is it permitted to play with the Limit 0,10, Limit 11,20 etc values, or out of the question.
Why would you need our permission for anything about your site?

Let me be facetious: No, you cannot change anything in that code. If you do, you'll be in big trouble, young man!



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks Sleipnir, point taken, always in enough trouble as it is. Is just my VB6 braincells trying to take over.

I keep looking at:
$limit = 'LIMIT ' .($pagenumber - 1) * $rows_per_page .',' .$rows_per_page;

and:

$query = "SELECT * FROM Orders $where $limit";

and thinking there must be an easier way round refilling a table after submission back. Cannot make out what the second .$rows_per_page does.

Regards
 
It's all part of the LIMIT clause of a SELECT statement. A query can read:

SELECT......LIMIT 30,10

which is an example of the form LIMIT [offset], [number]. In the example above, the LIMIT clause tells the server that of all the rows in the result set, sent back 10, and begin counting those 10 rows at the 31st record (the offset value begins counting rows at 0).

So the expression from my code you are quoting set the appropriate multiple of $rows_per_page as the starting place, and $rows_per_page as the number of rows to return.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks Sleipnir, that explains it well. Maybe I have been trying to be too clever in having all the code in one form/page, ie checkboxes for select WHERE statement etc,etc. Maybe I should have one page for doing this, and then submit to a page having Sleipnirs code in. Getting to hate this project by the minute, so near but so far away with it, but thanks both for the feedback.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top