Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By syawillim on
I'm using the following code to disply a list of nodes for recurring events. The site admin will just publish and unpublish as required.
My question is, should the H3 tag sill output if the query returns no result?
<?php
unset ($output);
$taxo_id = 12;
$list_no =5;
$sql = "SELECT node.title, node.nid FROM node INNER JOIN term_node ON node.nid = term_node.nid WHERE term_node.tid IN ($taxo_id) AND status = 1 ORDER BY node.created DESC LIMIT $list_no";
$result = db_query($sql);
if ($result) {
$output .= "<div id=\"events\">";
$output .= "<h3>Upcoming Events</h3>";
$output .= "<ul>";
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
$output .= "</div>";
}
print $output;
?>
Comments
If you want no output when no results use db_num_rows
If you onlu want output where there are rows returned changed the if to
Thank you nevets
Thank you nevets, it's just too easy when you know how.
www.slickfish.com.au
professional, affordable web site design, production and maintenance for small business