Reputation: 730
Get the latest 4 donations that come into the system .
Donation IDs are auto incremented (201 , 202, 203 , 204) .. therefore I wanted to order by DESC to get the latest 4 donations.
$resultsdonations = mysql_query("SELECT * FROM donationstable ORDER BY 'donation_id' DESC LIMIT 0,4 ");
Upvotes: 0
Views: 1227
Reputation: 125835
As the other answers have pointed out, you must remove the quotes from around donation_id
.
As it currently stands, you are not sorting by the value in the donation_id
column, but rather by the string literal 'donation_id'
, which is constant for each record and therefore results in an indeterminate ordering.
Upvotes: 0
Reputation: 49552
You don't need the quotes around donation_id
. Just use .. BY donation_id DE ..
Upvotes: 0
Reputation: 43434
Remove the apostrophes around 'donation_id'
and the 0
is unnecessary in the LIMIT
clause considering your requirement:
$resultsdonations = mysql_query(
"SELECT * FROM donationstable ORDER BY donation_id DESC LIMIT 4");
Upvotes: 2
Reputation: 8113
Try this:
$resultsdonations = mysql_query("SELECT * FROM donationstable ORDER BY donation_id DESC LIMIT 0,4 ");
(drop the ' around the donation_id column)
Upvotes: 0