Re: Sorting issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, kind of ugly but you can do something like this:

SELECT Position, CASE Position WHEN 'CEO' THEN 1 WHEN 'COO' THEN 2 WHEN 'CFO' THEN 3 WHEN 'HR' THEN 4 ELSE 99 END AS PositionSort
FROM SomeTable
ORDER BY PositionSort


That way you're not creating a whole new table to store the sorting values.

You can also just put the CASE sequence in your ORDER BY (I believe) so it doesn't get returned as a value.  Didn't test that, but it's a little thing either way.

-TG



= = = Original message = = =

I have been trying to figure out how to get this to work for a couple of
days.

 

I need to sort the results of a DB query based on the hierarchy of positions
within an organization. Since they are not necessarily alphabetical, the
best I can come up with is to assign a numerical value in a separate table
to each position, and reference that to sort it.

 

Is this the best way to do this? Or is there some other trick someone can
clue me in on?

 

My code now runs the query, and with a 

 

while ($row = mysql_fetch_assoc($result))



 *put results into an array*



 

statement I put each entry into an array

 

then I sort it like so.

 

array_multisort($array);

$count = 0;

while (isset ($array[$count]))



*display results in a table*

$count++;



 

 

 

Thanks,

 

Don


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux