Help with function in template.php
Your queries should look something like this:

$query = "SELECT t1.tid, t1.parent FROM {taxonomy_term_hierarchy} t1 JOIN {field_revision_field_pubissue} t2 ON t1.tid = t2.field_pubissue_tid WHERE t2.entity_id = :nid";
$result = db_query($query,array(':nid' =&gt; $node-&gt;nid));
// Result is returned as a iterable object that returns a stdClass object on each iteration (@see http://api.drupal.org/api/drupal/includes--database--database.inc/function/db_query/7#comment-7019)


After all I would suggest you check out the drupal taxonomy api. Using something like taxonomy_get_tree() could be much better.

EDIT:

Using the taxonomy api I would say what you want to do would be something like:

$parents = taxonomy_get_parents($tid);
if(!empty($parents)) {
    // use whatever you need from your $parents
}
else {
    $term = taxonomy_term_load($tid);
    // use whatever you need from the term (No parent, top level)
}


EDIT 2: fixed code example...