Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:21:21+00:00 2026-06-04T05:21:21+00:00

There is a PHP array populated from sorted records from a MySQL table :

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:21:23+00:00Added an answer on June 4, 2026 at 5:21 am
    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 IS NULL, cm.class_menu_lib, m.menu_titre
    

    Basically NOT NULL < NULL, so you add that as the first sort key.

    See in action: http://www.sqlfiddle.com/#!2/226a4/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any function available in PHP to check whether an array is empty
I'm interested if there is any function like array_map or array_walk from php. Don't
I come from a php background and in php, there is an array_size() function
I have populated an html form with MySQL data from a table. I have
I have a dropdown menu populated from a table in a MySQL database. It
There is an array of user states stored in the session. This works: <?php
How can I add all of my array values together in PHP? Is there
Is there a built-in function for PHP for me to check whether two arrays
Is there php function to remove the space inside the string? for example: $abcd=this
PROBLEM I have a nested PHP array that I need to populate from flat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.