There is a PHP array populated from sorted records from a MySQL table :
function recupererDroitCreateur($user_id, $isAdmin = null) {
$ret = array() ; // this will be the returned array
// Requête de sélection de tous les menus
$sSQL = "SELECT m.menu_code, m.menu_lib, m.menu_action, m.menu_titre, cm.class_menu_lib, cm.class_menu_code
FROM menu m
LEFT JOIN classe_menu cm
ON m.class_menu_code = cm.class_menu_code
WHERE m.menu_deleted = 0 AND m.menu_visible = 1
ORDER BY cm.class_menu_lib, m.menu_titre";
$this->db->query($sSQL) ;
$ret['cnt'] = $this->db->num_rows();
$i = 0;
while ( $this->db->next_record() ) {
$ret[$i]["menu_code"] = $this->db->f('menu_code');
$ret[$i]["menu_lib"] = stripslashes($this->db->f('menu_lib'));
$ret[$i]["menu_action"] = stripslashes($this->db->f('menu_action'));
$ret[$i]["menu_titre"] = stripslashes($this->db->f('menu_titre'));
$ret[$i]["class_menu_lib"] = stripslashes($this->db->f('class_menu_lib'));
$ret[$i]["class_menu_code"] = stripslashes($this->db->f('class_menu_code'));
$i++;
}
return ($ret);
}
There are null values in the “cm.class_menu_lib” column which is the sort column of the query. So when showing the contents of the array inside a html table then the null records are displayed first ! How to show the null records last ?
Basically
NOT NULL < NULL, so you add that as the first sort key.See in action: http://www.sqlfiddle.com/#!2/226a4/1