Re: [PHP-DB] Getting last row, moving backwards..
Hello Chad, 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! You may want to try this "Query result table display class" that lets you browse query results presenting them in a table with links to to the Next, Previous, First, Last and other pages of results if they don't fit in a single page. http://phpclasses.UpperDesign.com/browse.html/package/130 Manuel Lemos -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Getting last row, moving backwards..
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:[EMAIL PROTECTED]] Sent: Friday, January 19, 2001 10:26 AM To: Chad Day Cc: '[EMAIL PROTECTED]' 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Getting last row, moving backwards..
> -Original Message- > From: Chad Day [mailto:[EMAIL PROTECTED]] > Sent: Friday, January 19, 2001 9:15 AM > To: '[EMAIL PROTECTED]' > Subject: [PHP-DB] Getting last row, moving backwards.. > > > 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! Wouldn't it be easier to just get them from the database in the order that you want? In your example, something like select * from mytable order by id_field desc would likely do the trick (sorting your results by the value of the ID field, in descending order). --- Mark Roedel| "A wise man once told me that everything in Systems Programmer | life is either a lesson or a joke. Our task LeTourneau University | is to figure out which is which..." Longview, Texas, USA | -- Chris Savage -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Getting last row, moving backwards..
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! Chad Day Beach Associates When I speak german... I think german in my head... but like...Do skript kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in their h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]