Re: last ten from mysql?

From: Date: Thu, 13 Jul 2000 16:43:57 +0000
Subject: Re: last ten from mysql?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6495@lists.php.net to get a copy of this message
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

« previous php.general (#6495) next »