Re: retrieve last n records
| From: | Doug Parker | Date: | Fri, 07 Mar 2003 02:23:39 +0000 |
| Subject: | Re: retrieve last n records | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26150@lists.php.net to get a copy of this message | ||
OK, I would like to do it with the method you suggested. However, I'm having a few problems. Firstly, I can't seem to figure out how to sort rows returned from mysql_fetch_array. sort() or any other array function won't work because each row is an array, and I need to sort by the column. Secondly, which PHP classes website are you referring to? I don't even know how I would use a PHP class in conjunction with it if I did find the site. Thirdly, I do need to re-sort the data on-the-fly. Would this essentially be accomplished if I were just sorting the table data via PHP functions?
Thanks for your help.
Jim Hunter wrote:
If it were me I would tackle this in two parts. First create a SQL statement that returns the data you want, you say you can do this so the first part is already finished. Then stuff the data into an array and when you go to display the data to the user, that is when you sort it into the chosen sort order. It is not that hard to sort an array and you might be able to find a class already written to do this on the PHP classes web site. You might even go so far as to display the info in a table that allows the user to click on a column heading and re-sort the data on-the-fly without a round trip to the server. This might add a nice touch to your UI without too much effort. Jim -------Original Message------- From: drparker Date: Thursday, March 06, 2003 14:23:29 To: php-db@lists.php.net Subject: Re: [PHP-DB] retrieve last n records I need the last n records when, say user_id = 3. So it returns all rows where user_id = 3, then, on top of that I need only the n most recently entered records. The problem with the sorting mechanism I have existing is essentially that those last n rows need to be sorted ASC or DESC by every field. So basically, I need to be able to retrieve those last n rows where user_id = whatever, then be able to sort those last 3 rows ASC or DESC by any field. Jim Hunter wrote:I guess I am confused, how does one query effect a query that you have inan other part of the page? The two queries are not related. The secondthingI am confused on is: Do you want the last n records that were added to thetable or do you want the last n records in a given index?Jim-------Original Message-------From: drparkerDate: Thursday, March 06, 2003 13:46:58To: php-db@lists.php.netSubject: [PHP-DB] retrieve last n recordsI need to retrieve the last n records of a table, n will probably be 2or 3. I know that I can accomplish this by: select * from table orderby field DESC Limit n, but i would prefer not to do this way because itinterferes with my sorting mechanism on the main page. Is there anyother way to do it?--PHP Database Mailing List (http://www.php.net/)To unsubscribe, visit: http://www.php.net/unsub.php.