Re: last ten from mysql?
| From: | Jason Stechschulte | Date: | Thu, 13 Jul 2000 17:11:22 +0000 |
| Subject: | Re: last ten from mysql? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-6498@lists.php.net to get a copy of this message | ||
Be careful with the timestamp also. Using it will
give you the last 10 inserted or updated fields.
By default, everytime you update a field in a row
containing a timestamp, the first timestamp field
for that row will also be updated. Perhaps this
is what you want, perhaps not. You might just
want the last 10 inserted. If this is the case,
always update the timestamp field with its own
value, or use an auto_increment column.
Jason Stechschulte
jpstech@nc.edu
-----Original Message-----
From: Hans H. Anderson
[mailto:hans@hansanderson.com]
Sent: Thursday, July 13, 2000 12:44 PM
To: php-general@lists.php.net
Subject: Re: [PHP] last ten from mysql?
On Thu, 13 Jul 2000, Mike Bosschaert wrote:
> 1. get number to start with:
$start=mysql_num_rows($result)-10
> 2. include LIMIT statement in you SQL query:
SELECT bla bla FROM bla WHERE
> bla bla LIMIT $start, 10
> >I just want to select the last ten rows from a
mysql
> >database on a php page... what command would i
use???
Why don't you just use the LIMIT in one query? In
order to get the *last*
ten, you must have a field to order by. If you
aren't using order by,
then you can't reliably get the records you want.
So, say you have a
TIMESTAMP field, you could use this query,
ordering by desc to get the
last ones:
select * from Table order by Time_Stamp desc LIMIT
10;
- Hans
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail:
php-general-unsubscribe@lists.php.net
For additional commands, e-mail:
php-general-help@lists.php.net
To contact the list administrators, e-mail:
php-list-admin@lists.php.net