RE: [PHP-DB] Next N Interface
> That would actually work for just getting a certain number of records from > a > query, but you would have to execute another query to figure out the > navigational > links he said he wants on the bottom...like google has, << 1 2 3 4 5 >>. > So, > when I attacked it I figured one query is better then two even if it > returns a > whole bunch of records in the result that you are not using for that page. > How is > that for performance? which would be better? Or even, is there an > alternative > way to figureing out how many records are in a database? Always more then > one > way to skin a cat. Use two queries. A count(*) query and a LIMIT query to only return X rows. If you have a smaller table, it might be okay to do it with on and seek the rows you want, but it's inefficient and not scalable for large tables. Previous/Next links are pretty simple with MySQL. Just pass a $page variable between pages. Increment it with Next, decrement it with Previous. Then, use it in your query like this: $result1 = mysql_query("SELECT COUNT(*) FROM your_table WHERE ... "); $records = mysql_result($result,0); $num_per_page = 5; $start = $page * $num_per_page; $num_pages = ceil($records / $num_per_page); $result = mysql_query("SELECT * FROM your_table WHERE ... LIMIT $start, $num_per_page"); Add in a little logic so $page isn't below zero and doesn't go above your max pages, and you're golden... ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Next N Interface
That would actually work for just getting a certain number of records from a query, but you would have to execute another query to figure out the navigational links he said he wants on the bottom...like google has, << 1 2 3 4 5 >>. So, when I attacked it I figured one query is better then two even if it returns a whole bunch of records in the result that you are not using for that page. How is that for performance? which would be better? Or even, is there an alternative way to figureing out how many records are in a database? Always more then one way to skin a cat. -Brad Mark Lee wrote: > How about appending " LIMIT _GET[startrow],5" to the end of your query. > > The first parameter to LIMIT is the start position and the second is > the number of rows to return. > > Does this help, or am I misunderstanding your question? > > Mark > > Lucas Novæ Matrix wrote: > > >Hello, > > > >I am trying to create a "next n" interface through php4, using results from > >a mysql query. I did this in the past easily with ColdFusion, but this time > >it's a bit more complicated. > > > >What I need to do basicaly is to have only 5 results per page. The first > >page displays the 5 results and "Next Page >>>" at the bottom, the second > >page displays results 6 to 10 and displays "<<< Previous Page | Next Page > > > " , up until the last page that displays only the previous page, and the > > >last results (from 1 to 5). > > > >I don't necessarely need to have each page as a number at the bottom, just > >the previous and next links. All I need basically is to either get or output > >only 5 rows at a time, with only needing the $_GET['startrow'] variable. > > > >Can anyone help me? (or just throw me a link to an existing page/script) > > > >Thanks, > >Éric. > > > > > > > > -- > 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
Re: [PHP-DB] Next N Interface
How about appending " LIMIT _GET[startrow],5" to the end of your query. The first parameter to LIMIT is the start position and the second is the number of rows to return. Does this help, or am I misunderstanding your question? Mark Lucas Novæ Matrix wrote: >Hello, > >I am trying to create a "next n" interface through php4, using results from >a mysql query. I did this in the past easily with ColdFusion, but this time >it's a bit more complicated. > >What I need to do basicaly is to have only 5 results per page. The first >page displays the 5 results and "Next Page >>>" at the bottom, the second >page displays results 6 to 10 and displays "<<< Previous Page | Next Page > " , up until the last page that displays only the previous page, and the >last results (from 1 to 5). > >I don't necessarely need to have each page as a number at the bottom, just >the previous and next links. All I need basically is to either get or output >only 5 rows at a time, with only needing the $_GET['startrow'] variable. > >Can anyone help me? (or just throw me a link to an existing page/script) > >Thanks, >Éric. > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Next N Interface
I did something like this with a photo gallery I made. The approach I took is the execute a query, get the number of rows, and divide that number by how ever many records I wanted on that page. Then that would give me the number of total pages I would have for my navigational links at the bottom. Then I would pass a page number from page to page and multiply this by the number of records which would give me the first record to display from the same query. Soem sample code: (I displayed 4 pictures/records per page) $num_rows = mysql_num_rows($result); //Check to see if any rows are present if ($num_rows <= 0) { echo "No Pictures Available in this Album"; exit(1); } $x = ($num_rows/4); $y = intval($x); if ($x > $y) { $num_pages= $y+1; } else { $num_pages= $x; } $curr_row = ($curr_page*4); if ($DEBUG > 0) { echo "Curr_row is: $curr_row"; } mysql_data_seek($result, $curr_row); HTH -Brad "Lucas Novæ Matrix" wrote: > Hello, > > I am trying to create a "next n" interface through php4, using results from > a mysql query. I did this in the past easily with ColdFusion, but this time > it's a bit more complicated. > > What I need to do basicaly is to have only 5 results per page. The first > page displays the 5 results and "Next Page >>>" at the bottom, the second > page displays results 6 to 10 and displays "<<< Previous Page | Next Page > >>>" , up until the last page that displays only the previous page, and the > last results (from 1 to 5). > > I don't necessarely need to have each page as a number at the bottom, just > the previous and next links. All I need basically is to either get or output > only 5 rows at a time, with only needing the $_GET['startrow'] variable. > > Can anyone help me? (or just throw me a link to an existing page/script) > > Thanks, > Éric. > > -- > 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
[PHP-DB] Next N Interface
Hello, I am trying to create a "next n" interface through php4, using results from a mysql query. I did this in the past easily with ColdFusion, but this time it's a bit more complicated. What I need to do basicaly is to have only 5 results per page. The first page displays the 5 results and "Next Page >>>" at the bottom, the second page displays results 6 to 10 and displays "<<< Previous Page | Next Page >>>" , up until the last page that displays only the previous page, and the last results (from 1 to 5). I don't necessarely need to have each page as a number at the bottom, just the previous and next links. All I need basically is to either get or output only 5 rows at a time, with only needing the $_GET['startrow'] variable. Can anyone help me? (or just throw me a link to an existing page/script) Thanks, Éric. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php