RE: [PHP] last ten from mysql?

From: Date: Thu, 13 Jul 2000 13:38:51 +0000
Subject: RE: [PHP] last ten from mysql?
Groups: php.general 
Request: Send a blank email to php-general+get-6436@lists.php.net to get a copy of this message
> >I just want to select the last ten rows from a mysql > >database on a php page... what command would i use??? > 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 Or you can do this so as to not require 2 queries: $query = "SELECT field FROM table ORDER BY field DESC"; $result = mysql( $dbname, $query ); if(( $result ) && ( mysql_errno() == 0 )) { for( $i = 0; $i < 10; $i++ ) { echo mysql_result( $result, $i, "field" ); } } But this is only useful if you don't mind going in reverse order... Chris

« previous php.general (#6436) next »