• Hi *,

    I am trying to sort a table from my wordpress plugin with this query:

    global $wpdb;
    $table_name = $wpdb->prefix . 'mytablename';
    $myentries = $wpdb->get_results("SELECT * FROM $table_name ORDER BY date DESC");

    But the “ORDER BY” seems to have no effect. It is still sorted last in first out (by id). Is there something that I’m overlooking in the documentation ?? -> http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If you’re getting results, the issue is not with the Codex documentation. If you feel the results are incorrect, the issue would be in how you constructed the query.

    Keep in mind that the sort order for id is often the same as for date. Or are you saying you are seeing id ascending, so the order is reverse of what you want?

    Is date really the correct column name for your table? You should change it, I believe that is a reserved SQL word. mySQL will let you build tables with reserved words, but queries will not work right.

Viewing 1 replies (of 1 total)
  • The topic ‘Using ORDER BY-query with generic results’ is closed to new replies.