Working from info discussed here: http://www.phpbuilder.com/board/showthread.php?s=&threadid=10280927, if you're curious

I have an array created by adding the results of two MySQL queries,

while($row = mysql_fetch_array($result1)) {
$new[] = array($row['name'] => $row['ID']);
}
while($row2 = mysql_fetch_array($result2)) {
$new[] = array($row2['name'] => $row2['ID']);
}

to create structure like this:

[43] => Array ( [a name] => an ID )

Everything else is working, but I can't figure out how to sort everything by the name field without losing the association.

I'd be glad of some suggestions.

    <?php
    $temp = array();
    foreach($new as $record) {
        $temp[] = $record['name'];
    }
    
    asort($temp);
    
    $temp2 = array_keys($temp);
    
    $sorted_new = array;
    
    foreach($temp2 as $id) {
        $sorted_new = $new[$id];
    }
    $new = $sorted_new;
    
    unset($temp2);
    unset($temp);
    unset($sorted_new);
    ?>

      The [man]usort[/man] page (including some of the user notes) might be of help, also.

        The above suggestion outputs a single line "array" which contains only the data from the last row:

        Array ( [last name from source array] => last ID )

        Off to read the usort page again.

          Write a Reply...