How can I set a default sort for tables in PHPMyAd

2019-01-12 05:39发布

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% of the time I would rather have the newest data (my test data) shown at the top by default rather than the useless first few records ever saved.

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

7条回答
做个烂人
2楼-- · 2019-01-12 06:07

i think you can do this. Go to a table -> operations and set alter table order by descending. Next time when ever you browse you get the newest row first.

查看更多
ら.Afraid
3楼-- · 2019-01-12 06:15

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.

查看更多
祖国的老花朵
4楼-- · 2019-01-12 06:19

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.

查看更多
地球回转人心会变
5楼-- · 2019-01-12 06:19

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.

查看更多
smile是对你的礼貌
6楼-- · 2019-01-12 06:25

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/

查看更多
戒情不戒烟
7楼-- · 2019-01-12 06:29

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.

查看更多
登录 后发表回答