>I've read the manual several times on sorting multi-dimensional arrays,
>but I can't seem to wrap my mind around what I need to do to accomplish
>my goal.
>
>//this is what I'm doing: (stepping through a result set, and putting it
>into a multi-dimensional array.
>
>while ($row = mysql_fetch_array($result)) {
>       $docs[$counter][doc_id] = $row[doc_id];
>       $docs[$counter][doc_name] = $row[doc_name];
>       $docs[$counter][clinic_id] = $row[clinic_id];
>       $docs[$counter][clinic_name] = $row[clinic_name];
>       $counter++;
>} //end while
>
>//now, I want that array sorted by the clinic_name, and then doc_name.

Not to be a stinker, but why not just do the sorting in your mysql query?

        select * from your_table order by clinic_name, doc_name;

If sorting in PHP is what you really need to do, the answer is to not use
array_multisort. Use usort() instead, with a function that compares
arguments based on clinic_name and doc_name (code untested):

        function compare_docs($a, $b)
        {
            if($a['clinic_name'] === $b['clinic_name'])
                return(strcmp($a['doc_name'], $b['doc_name']);
            return(strcmp($a['clinic_name'], $b['clinic_name']);
        }
        while($row = mysql_fetch_array($result))
                $docs[$counter++] = $row;
        usort($docs, 'compare_docs');

---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html

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

Reply via email to