Reputation: 13
<?php
$result = @mysql_query('SELECT Article FROM news WHERE ID = (SELECT MAX(ID) FROM News)');
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
echo('<p>' . $row['Article'] . '</p>');
}
?>
Basically, I need to tweak this code, so that it shows the latest three results instead of just the latest one, the newest being the first.
Upvotes: 0
Views: 4744
Reputation: 3947
this query ?
SELECT Article FROM News ORDER BY ID DESC LIMIT 3
Upvotes: 1
Reputation: 237845
Have a go with this query:
$result = @mysql_query('SELECT Article FROM news ORDER BY ID DESC LIMIT 3');
FWIW, you may like to sort out the capitalisation of your database columns. The inconsistency will cause you problems in future.
Upvotes: 1
Reputation: 3731
in mysql query add limit
select * from table order by id desc limit 0,3
Upvotes: 5