ciao,

ho una funzione che mi estrae in una combo le categorie.
se le ordino con ORDER BY cat_id, mi visualizza tutte le categorie, ma se le ordino BY cat_name ne perdo alcune.
per esempio, se ho categorie che vanno da A-Z, ORDER BY cat_name inizia a contarmele da C.
La query funziona, l'ho provata quindi dev'esserci qualcosa nella funzione che non va
:master:
posto il codice:


Codice PHP:
function buildCategoryOptions($catId 0)
{
    
$sql "SELECT cat_id, cat_parent_id, cat_name
            FROM tbl_category
            ORDER BY cat_name"
;
    
$result dbQuery($sql);

    
$categories = array();
    while(
$row dbFetchArray($result)) {
        list(
$id$parentId$name) = $row;

        if (
$parentId == 0) {
            
// we create a new array for each top level categories
            
$categories[$id] = array('name' => $name'children' => array());
        } else {
            
// the child categories are put int the parent category's array
            
$categories[$parentId]['children'][] = array('id' => $id'name' => $name);
        }
    }

    
// build combo box options
    
$list '';
    foreach (
$categories as $key => $value) {
        
$name     $value['name'];
        
$children $value['children'];

        
$list .= "<optgroup label=\"$name\">";

        foreach (
$children as $child) {
            
$list .= "<option value=\"{$child['id']}\"";
            if (
$child['id'] == $catId) {
                
$list.= " selected";
            }

            
$list .= ">{$child['name']}</option>\r\n";
        }

        
$list .= "</optgroup>";
    }

    return 
$list;