By wdrupal on
This is a modification of a PHP snippet that I found in one of the handbooks. I want it to list the 4 most recent titles, decending. The error happens when I add the ORDER BY node.created DESC. Is that a mistake?
<?php
// only the four latest titles here:
$node_type = "story";
$list_no = 4;
$sql = "SELECT node.title, node.type, node.nid, node.created FROM node WHERE node.type = '$node_type' LIMIT $list_no ORDER BY node.created DESC";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
print $output;
?>
Comments
Fixed it
Found the error.
If anyone comes across this thread, the way to do it is this: "ORDER BY" comes before "LIMIT".
How to list node titles on front_page with most recent node titles first.