Damnit.
Forgot to cc to the list, again. Here it is.
---------- Forwarded Message ----------
On Monday 14 January 2002 12:55, you wrote:
> hi guys, just looking for verification on this, as i don't think there's
> any way to do it....
>
> Basically, i want to return the results for a search, but only return the
> first 20 results from the start number given....
> LIMIT $start, 20
> BUT... i'd like to have a page 1-whatever so if there are 65 results in
> total, then the first 20 will be shown, but there will be options to move
> to pages 2,3 or 4.
> Obviously, if i use LIMIT, then it won't know that there are 65 in total,
> so how would i get around this? do i just have to do the full query, and
> then only use the first 20 results in the results set?
> just becomes a bit of a problem if there are, say, 8000 results returned!
> would it just be best to return the first 200 using LIMIT, and do my pages
> for those, with a note that there are more than 200 results, and to refine
> the search criteria?
> Cheers,
> Matt
Matt,
Here's how I did the "20 results per page". Messy, I know, but
it was the only way I figured out how to do it.
$query="SELECT * FROM table";
$result=mysql_query($query,$database);
$nr=mysql_num_rows($result);
/* Here you can slap in a check for how many results
you want, ie:
*/
if($nr>200) {
die("Bitch,whine and moan!");
}
$nr_pages=(ceil($nr/20));
Or, you could, in the first SELECT statement put in a
LIMIT 200, I suppose that would work, too.
I'd have to dig into this myself too, as my database will
have a tad over 100 000 records when it's done.
Then I have two buttons, prev & next that's got a little
javascript slapped on them;
<INPUT TYPE=button VALUE="previous page"
onclick="parent.location='nav.php?nav=true&go=prev';">
etc.
Then, in nav.php:
if($go=="next") {
if($page < $nr_pages && $page >= 0) {
$page++;
$with= (($page) * 20).",";
$what = (($page-1) * 20).",";
$query=ereg_replace($what,$with,$query);
}
}
if($go=="prev") {
if($page>=1 && $page <= $nr_pages) {
$page--;
$with = (($page) * 20).",";
$what = (($page+1) * 20).",";
$query=ereg_replace($what,$with,$query);
}
}
$result=mysql_query($query,$database)
print_table(); //processes the query
If you got any questions regarding my code,
please do drop me a mail.
Cheers,
Markus
-------------------------------------------------------
--
Markus Lervik
Linux-administrator with a kungfoo grip
Vaasa City Library - Regional Library
[EMAIL PROTECTED]
+358-6-325 3589 / +358-40-832 6709
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]