Re: retrieve last n records

From: Date: Thu, 06 Mar 2003 21:53:15 +0000
Subject: Re: retrieve last n records
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138537@lists.php.net to get a copy of this message
----- Original Message ----- From: "drparker" <drparker@camden.rutgers.edu> To: <php-general@lists.php.net> Sent: Thursday, March 06, 2003 2:42 PM Subject: [PHP] retrieve last n records > I need to retrieve the last n records of a table, n will probably be 2 > or 3. I know that I can accomplish this by: select * from table order > by field DESC Limit n, but i would prefer not to do this way because it > interferes with my sorting mechanism on the main page. Is there any > other way to do it? Retrieve your records as normal and using mysql_data_seek() to move the results pointer to the desired row then start your loop. http://www.php.net/manual/en/function.mysql-data-seek.php Please note this is not an efficient way to accomplish the goal. LIMIT is certainly the way to go and you should be able to do any sorting you need within the SQL statement. After all retrieving, ordering and grouping database information is what SQL was designed to do. - Kevin

« previous php.general (#138537) next »