How to get node.tpl.php to display different content for different nodes? 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:

&lt;?php
  $db = mysql_connect('localhost', 'root', '');
  mysql_select_db('sage', $db);
  $query = "show tables";
  $db_query = mysql_query($query, $db);
  echo "&lt;TABLE border = '1'&gt;";
  echo "&lt;TR&gt;";
  echo "&lt;TH&gt;TABLE NAME&lt;/TH&gt;";
  echo "&lt;/TR&gt;";
  while($row = mysql_fetch_array($db_query)) {
      $tableName = $row[0];
      echo "&lt;TR&gt;";
      echo "&lt;TD&gt;&lt;a href=/node/5/$tableName&gt;$tableName&lt;/a&gt;&lt;/TD&gt;";
      echo "&lt;/TR&gt;";
  }  
  echo "&lt;/TABLE&gt;";
?&gt;


Do I copy and paste this code directly into node.tpl.php?
I don't See any node id in your code. If all you want is to have PHP generated output for an URL, define the path with hook_ menu() and just return the generated HTML from the call back method.