How can I set a default sort for tables in PHPMyAdmin (i.e. always “Primary key - Descending”)

后端 未结 7 1015
情书的邮戳
情书的邮戳 2020-12-11 01:19

Even though its obnoxious in a lot of ways I use PHPMyAdmin all the time to debug database issues while writing PHP. By default it sorts tables by primary key ascending. 99%

相关标签:
7条回答
  • 2020-12-11 01:29

    Why don't you use heidi SQL

    Here's a guide on how:

    Enable login from your host pc.

    First of all, get your IP Address - http://www.whatismyip.com Hopefully that's a static IP, otherwise you have some less secure options (below)

    You'll need access to create a user on the database. You can do this through Cpanel, or in PHP My Admin (assuming you have the right level of access). Google for instructions if you are unsure. Fail that you can attemtp to run this query:

    CREATE USER 'jason'@'your_ip_here' IDENTIFIED BY 'your_password_here';
    GRANT ALL PRIVILEGES ON database_name.* TO 'jason'@'your_ip_here';
    

    If you don't have a static IP Address then you can consider using a wildcard, although this is less secure. Another more secure option is SSH tunneling

    Download and install Heidi SQL

    http://www.heidisql.com/download.php

    Run the install (on windows ofcourse)

    Finally, setup your connection, connect.

    You'll find that heidi allows you to easily sort the listing of data, http://www.heidisql.com/screenshots.php?which=data It also remembers sorts and filters too.

    0 讨论(0)
  • 2020-12-11 01:31

    I'm using phpMyAdmin version 4.2.3 (English) and I simply updated the sort order variable on line 488 in the DatabaseInterface.class.php file which resides in the Libraries directory. The line number (and possibly the file) may vary in other versions.

    public function getTablesFull($database, $table = false,
        $tbl_is_group = false,  $link = null, $limit_offset = 0,
        limit_count = false, $sort_by = 'Name', $sort_order = 'DESC',
        $tble_type = null
    

    The variable $sort_order was equal to 'ASC' when I opened the file. Since changing it to DESC and uploading via FTP, the sort order for my table (which is uniquely keyed on date (DATETIME) is always DESC (most recently added records first).

    Not sure if this is the best solution for all cases, but it suits my needs.

    Hopefully this helps.

    0 讨论(0)
  • 2020-12-11 01:32

    For anyone else who comes here looking for an answer:

    In phpMyAdmin 4.5.0, maybe in earlier versions too, you can set the $cfg['TablePrimaryKeyOrder'] config like so:

    $cfg['TablePrimaryKeyOrder'] = 'DESC';
    

    This defines the default sort order for the tables, having a primary key, when there is no sort order defines externally. Acceptable values : [‘NONE’, ‘ASC’, ‘DESC’]

    This sets the default sort if the table has a primary key and that no other sort has been applied to it.

    0 讨论(0)
  • 2020-12-11 01:36

    @jeremyclarke, in phpMyAdmin v3.4.5, after login click "home" then, from "More" menu choose "Settings" click "Main frame" tab, then "Browse mode" tab

    There you'll find "Default sorting order" the default mode is set to SMART hence, choose "ASC" or "DESC"

    If you do the above steps, it will be saved for the current session,

    to save it permanently set it in config.php http://wiki.phpmyadmin.net/pma/Config#Order

    0 讨论(0)
  • 2020-12-11 01:39

    By default it sorts tables by primary key ascending

    phpMyAdmin isn't performing any sorting at all by default. It's simply asking for all records in a table and MySQL is deciding the order.

    Is there a way to configure PHPMyAdmin to show the newest records by default? To alter similar behavior?

    There's no way to do this as phpMyAdmin would have to be informed about every primary key of every table (assuming there is one, and only one) and how to sort it.

    phpMyAdmin does support bookmarking queries. You could DESC and then bookmark that. However, it certainly won't minimize the number of clicks, if that's what you're aim is.

    http://www.phpmyadmin.net/documentation/

    0 讨论(0)
  • 2020-12-11 01:45

    You can save a private bookmark with the name of the table you're browsing.

    See https://phpmyadmin.readthedocs.org/en/latest/faq.html#bookmarks-can-i-execute-a-default-bookmark-automatically-when-entering-browse-mode-for-a-table

    6.22 Bookmarks: Can I execute a default bookmark automatically when entering Browse mode for a table?

    Yes. If a bookmark has the same label as a table name and it’s not a public bookmark, it will be executed.

    0 讨论(0)
提交回复
热议问题