assign("subnet_id", $subnet_id); // get subnet details for title $sql = "SELECT CONCAT_WS('/',subnet_address,subnet_mask) AS subnet FROM subnet WHERE subnet_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$subnet_id]); $smarty->assign("subnet", $sth->fetchColumn()); } else { $smarty->assign("subnet_id", ''); } // create sql with optional filter $where = join(' AND ', $w); $sql = "SELECT a.asset_id, CONCAT(LEFT(a.asset_info,30), IF(CHAR_LENGTH(a.asset_info)>30,'...','')) AS asset_info, REPLACE(a.asset_name, ' ', ' ') AS asset_name, n.node_id, n.node_ip, CONCAT(LEFT(n.node_info,30), IF(CHAR_LENGTH(n.node_info)>30,'...','')) AS node_info FROM node AS n LEFT JOIN asset AS a USING (asset_id)"; if ($where) { $sql .= ' WHERE ' . $where; } $sql .= "GROUP BY n.node_id ORDER BY INET_ATON(n.node_ip)"; $sth = $dbh->prepare($sql); $sth->execute($p); $smarty->assign("nodes", $sth->fetchAll()); $smarty->display("node.tpl"); include("footer.php"); ?>