Error on when to load node? I have problem when our taxonomy term is linked with node but when i am clicking on term they go front page of site instead of current page
our code given below: 

$ch1 = 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 = $ch AND book.entity_id = $nid
 ")-&gt;FetchField();

$chap1=taxonomy_get_children($ch1);
foreach($chap1 as $ca1){
    $link = l($ca1-&gt;name, 'node/' . $ca1-&gt;nid)."&lt;br&gt;";
    print $link;
}


How to handle this problem?
"$ch1" contain tids.

The function "taxonomy_get_children($ch1);" retrieve all children term id and not related nid...

You can retrieve all nid linked with a term with this function taxonomy_select_nodes 

I will suppose $ch1 contain your tids in an array

foreach($ch1 as $tid){
    $nids  = taxonomy_select_nodes($tid);
    $nodes = node_load_multiple($nids);
    foreach($nodes as $node){
        $link = l($node-&gt;title, 'node/' . $node-&gt;nid)."&lt;br&gt;";
        print $link;
    }
}


I can't test this code, if it's valid tell me and i will remove this line :)