RE: [PHP-DB] Getting last row, moving backwards..

From: Date: Fri, 19 Jan 2001 15:51:15 +0000
Subject: RE: [PHP-DB] Getting last row, moving backwards..
Groups: php.db 
Request: Send a blank email to php-db+get-5985@lists.php.net to get a copy of this message
cool, that's what I think I need (the data seek bit).. I'm not displaying them all on one page, it's like display a row, go to the next page, display the next row, repeat. I'll try it out, thanks a lot. Chad -----Original Message----- From: Andrew Rush [mailto:andy@mainetoday.com] Sent: Friday, January 19, 2001 10:26 AM To: Chad Day Cc: 'php-db@lists.php.net' Subject: Re: [PHP-DB] Getting last row, moving backwards.. On Friday, January 19, 2001, at 10:15 AM, Chad Day wrote: > I need some help selecting the last row in my database, and then moving > backwards.. I can't just get mysql_num_rows and go back by 1, as some of the > records are missing.. the ID field might have #'s like 1950, 1948, 1947, > 1944, etc, and I don't want it to break by mistakingly trying to grab 1949. > Can someone provide some help or a link to where in the manual what I'm > doing might be explained? Been searching, no luck yet. Thanks! the best thing to do is to select the results in the inverse order, by using the desc keyword with the order by clause. SELECT * FROM myTable WHERE something='somethingElse' ORDER BY id DESC but if that won't work do: $query="select ... $result=mysql_query($query); $rowTotal=mysql_num_rows($result); for($i=$rowTotal; $i > 0; $i=($i-1)) { $jumpTo=mysql_data_seek($rowTotal, $result); // arguments may be in the wrong order $row=mysql_fetch_array($result); } have a great day, andy :: Andrew Rush :: Lead Systems Developer :: MaineToday.com :: ************************************************************************** "Crippled but free, blind all the time, i was learning to see" - J. Garcia / R. Hunter ************************************************************************** The views expressed herein are not necessarily those of my employer, but they let me have them anyway. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#5985) next »