> 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

Reply via email to