How to link taxonomy term with its content? This is the code below that i am used

$ch=db_query("SELECT th.tid FROM taxonomy_term_hierarchy th 
  INNER JOIN taxonomy_term_data td ON th.tid=td.tid
  INNER JOIN field_data_field_books book ON book.field_books_tid = th.tid
  WHERE td.vid = '6' AND th.parent = $tid AND book.entity_id = $nid")-&gt;FetchField();

"&lt;h1&gt;Pages&lt;/h1&gt;";

$chap = taxonomy_get_children($ch);
foreach($chap as $ca){
  print "&lt;br&gt;Chapter===&gt;".$ca-&gt;name;
}


how I link taxonomy terms using the above code?
In Drupal 7 you can use l()

  $ch = db_query("SELECT th.tid FROM taxonomy_term_hierarchy th 
        INNER JOIN taxonomy_term_data td ON th.tid=td.tid 
        INNER JOIN field_data_field_books book ON book.field_books_tid = th.tid
        WHERE td.vid = '6' AND th.parent = $tid AND book.entity_id = $nid")-&gt;FetchField();

  $chap = taxonomy_get_children($ch);
  foreach ($chap as $ca) {
    print l($ca-&gt;name, 'taxonomy/term/' . $ca-&gt;tid);
  }