为什么这个查询没有给我最近插入的行?

I have this code working 100%, but it doesn't show the latest details required from the MySQL database.

$SQL = "SELECT * FROM wdclients ORDER BY 'id' DESC LIMIT 6";
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)) {
    echo $latest1;
    print $db_field['clientid'];
    echo $latest2;
    print $db_field['cname'];
    echo $latest3;
    print $db_field['cname'];
    echo $latest4;
}

The problem now is that I require the code to show only the 6 latest entries in the database. I have over 500 clients in the database but it only shows the first 6 and never update.

The "ID" field in database has set the auto-increment value.

as @BN said, remove quote around id. Make your query like this:

SELECT * FROM wdclients ORDER BY id DESC LIMIT 0,6

or, if you insist, change it into something like this:

SELECT * FROM wdclients ORDER BY `id` DESC LIMIT 0,6

notice the difference between ( ' ) and ( ` )

Although it usually does the trick, sorting by id is no guarantee to get the latest data entered. You'd better add a DATETIME field like date_created or date_updated that contains a timestamp when the record was either inserted or last updated, depending on your wishes. That way you'll be sure to get the data in proper chronological order.

It's because you have put id in regular single quotes. You have to use backquotes in order for MySQL to parse it into a value:

$SQL = "SELECT * FROM wdclients ORDER BY `id` DESC LIMIT 6";

Your first problem is that you used single quotes instead of backticks to delimit that field name.

SELECT * FROM wdclients ORDER BY `id` DESC LIMIT 6

Ordering by a string literal ('id') doesn't really do anything, so you ended up with the "natural" ordering.

That is, the physical ordering in storage, since MySQL tables have no inherent ordering. And, even though you set AUTO_INCREMENT on that ID field, it is not guaranteed to yield sequential values forever (e.g. IDs from old, deleted rows could be used).

You should set the ID yourself with a known unique, sequential value if you want to define an actual ordering by insert time.