Re: Next and Preview Row
| From: | Fournier Jocelyn [Presence-PC] | Date: | Fri, 22 Feb 2002 20:14:29 +0000 |
| Subject: | Re: Next and Preview Row | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-85889@lists.php.net to get a copy of this message | ||
Hi,
It seems worst to me because in your case mysql has to retrieve all the
rows.
If it's a table with 1 million records or more, this should hurt ;)
Regards,
Jocelyn Fournier
Presence-PC
----- Original Message -----
From: "Chris Boget" <chris@wild.net>
To: "Raymond Gubala" <gubala@dca.durhamc.on.ca>; "Mark Lo"
<markloky@netvigator.com>; <mysql@lists.mysql.com>;
<php-general@lists.php.net>
Sent: Friday, February 22, 2002 4:45 PM
Subject: Re: [PHP] Next and Preview Row
> > The solution I have been using is to do three queries similar to the
below
> > SELECT * FROM table WHERE field='ID00025'
> > SELECT * FROM table WHERE field<'ID00025' ORDER BY field DESC LIMIT 0,1
> > SELECT * FROM table WHERE field>'ID00025' ORDER BY field ASC LIMIT 0,1
> > If you whish more row returned change the number in the LIMIT
>
> Why bother with 3 queries? It's a waste of resources, especially if
> you are working with the same record set...
>
> Example (pseudo)code:
>
> <?
>
> $query = "SELECT * FROM table";
> $result = mysql( $dbname, $query );
>
> for( $i = 0; $i < mysql_num_rows( $result ); $i++ ) {
> echo "Previous field: " . mysql_result( $result, ( $i - 1 ),
"field" );
> echo "Current field: " . mysql_result( $result, $i, "field" );
> echo "Next field: " . mysql_result( $result, ( $i + 1 ), "field" );
>
> }
>
> ?>
>
> Chris
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
> To request this thread, e-mail <mysql-thread100751@lists.mysql.com>
> To unsubscribe, e-mail
<mysql-unsubscribe-joc=presence-pc.com@lists.mysql.com>
> Trouble unsubscribing? Try:
> http://lists.mysql.com/php/unsubscribe.php
>
>