Re: Re: sorting results in PHP
| From: | Doug Thompson | Date: | Tue, 18 Mar 2003 13:39:36 +0000 |
| Subject: | Re: Re: sorting results in PHP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26445@lists.php.net to get a copy of this message | ||
Without knowing your query, it is hard to say whether mysql can return the results you want.
However, you can GROUP BY and SORT BY multiple columns in a single query. The following simple
query returns a subset of property owners grouped by lastname, alpabetized by group, and ordered by
zipcode from a database I have at hand. Mysql Version 4.0.1a
select last_name, zipcode from mytable where last_name like "sm%" group by last_name,
zipcode order by last_name, zipcode;
You could simplify your life by combining your y,m,d fields into a single DATE type, too.
Doug
On Tue, 18 Mar 2003 10:36:40 +0200, Edwin Boersma wrote:
>What about making an array with dates, that you compiled from Year,
>Month, Date using mktime(), and sort that?
>
>Edwin
>
>Bill wrote:
>> I have a query that returns results including the fields Year, Month, and Day
>> that I want to sort by date.
>>
>> Because of the nature of the query (it includes a GROUP BY statement), I cannot
>> sort it in the query.
>>
>> How can I sort the results?
>>
>> I tried to use asort() while designating the field but that didn't work.
>>
>> while ($crow=mysql_fetch_array($cresult)) {
>> $therow[]=$crow;
>> }
>> asort($therow["Year"]);
>> reset($therow);
>> asort($therow["Month"]);
>> reset($therow);
>> asort($therow["Day"]);
>> reset($therow);
>>
>> ideas?
>>
>> kind regards,
>>
>> bill
>>
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>