Am I usort-ing correctly?
| From: | Melissa Tonelli | Date: | Thu, 22 Jun 2000 14:03:26 +0000 |
| Subject: | Am I usort-ing correctly? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-2621@lists.php.net to get a copy of this message | ||
Hello, all.
I have a table that stores information on the number of employees at approximately 300+ companies, 200 of which are companies of a certain type (let's say retailers). I generate rankings on the fly by having my query ORDER by #_employees DESC. This eliminates the need of having to maintain a "ranks" field in the db, but it raises a new problem for me.
I need to present a list of the 200 retailers alphabetically, but first broken into two halves i.e., the biggest 100 retailers sorted alpha, the remaining 200 retailers sorted alpha. I couldn't think of a way to do this in MySQL -- if someone knows a way, that would be great.
What I'm attempting instead is to run the ranking query (which I can LIMIT to break the list in half), then usort the returned array. But I can't make it work (wrong datatype in usort() call). I think there's something wrong with the variable I'm using in my strcmp?? Here's the code. Any hints/suggestions greatly appreciated (as always).
$result = mysql_query("SELECT DISTINCT CoID, Co, FROM Cos WHERE CoType='Retailer' ORDER BY CoEmps DESC LIMIT 100");
function co_sort($a,$b) {
return strcmp($result['Co']);
}
usort($result, co_sort);
---
mtonelli@bway.net
phone 718 728 7567 * fax 718 728 4420