I currently display some database content through PHP code written directly in the body of several nodes.
I would like to shift this code into node.tpl.php (as I have seen from the Zen examples that code to modify a node should be in node.tpl.php). However, I have multiple nodes, each displaying different kinds of database content.
How should I structure the code in node.tpl.php so that if it is Page A, then I display database content A and if it is Page B, then display database content B?
As an example.
Currently I have the following in one of my node body:
<?php
$db = mysql_connect('localhost', 'root', '');
mysql_select_db('sage', $db);
$query = "show tables";
$db_query = mysql_query($query, $db);
echo "<TABLE border = '1'>";
echo "<TR>";
echo "<TH>TABLE NAME</TH>";
echo "</TR>";
while($row = mysql_fetch_array($db_query)) {
$tableName = $row[0];
echo "<TR>";
echo "<TD><a href=/node/5/$tableName>$tableName</a></TD>";
echo "</TR>";
}
echo "</TABLE>";
?>
Do I copy and paste this code directly into node.tpl.php?