I have some PHP code to get info from a database.

$category='New Boats';
$titles=array();
$result=db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE name = :type',array(':type' => 'Boat Types'));
$row = $result->fetchAssoc();//8
$vid=$row['vid'];
$tid=db_query('SELECT tid,name FROM {taxonomy_term_data} WHERE vid=:vid',array(':vid' => $vid));
while($ttd_row= $tid->fetchAssoc()){
  if($ttd_row['name']==$category){
    $tid=$ttd_row['tid'];
    $result=db_query('SELECT entity_id FROM {field_data_field_boat_type} WHERE field_boat_type_tid=:tid',array(':tid'=> $tid));
    $eRows=$result->fetchAssoc();
    $eid=$eRows['entity_id'];
    $result=db_query('SELECT title FROM {node} WHERE nid=:nid',array(':nid'=>$eid));
    $eRows=$result->fetchAssoc();
    $titles[$eid]=$eRows['title'];
  }
print_r($titles);//<------- This outputs the contents of the array.
}

The above code prints out the contents of the $titles array.

However, this produces a blank page:

$category='New Boats';
$titles=array();
$result=db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE name = :type',array(':type' => 'Boat Types'));
$row = $result->fetchAssoc();//8
$vid=$row['vid'];
$tid=db_query('SELECT tid,name FROM {taxonomy_term_data} WHERE vid=:vid',array(':vid' => $vid));
while($ttd_row= $tid->fetchAssoc()){
  if($ttd_row['name']==$category){
    $tid=$ttd_row['tid'];
    $result=db_query('SELECT entity_id FROM {field_data_field_boat_type} WHERE field_boat_type_tid=:tid',array(':tid'=> $tid));
    $eRows=$result->fetchAssoc();
    $eid=$eRows['entity_id'];
    $result=db_query('SELECT title FROM {node} WHERE nid=:nid',array(':nid'=>$eid));
    $eRows=$result->fetchAssoc();
    $titles[$eid]=$eRows['title'];
  }
}
print_r($titles);//<------------ No output, just a blank page.

Can anyone see what I'm doing wrong?

I'm asking here.

Why should I go to another forum and ask the same question?

Anyway, I've solved it.

$category='New Boats';
$titles=array();
$result=db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE name = :type',array(':type' => 'Boat Types'));
$row = $result->fetchAssoc();//8
$vid=$row['vid'];
$ttd=db_query('SELECT tid,name FROM {taxonomy_term_data} WHERE vid=:vid',array(':vid' => $vid));//<----- varaible name changed from $tid to $ttd
while($ttd_row= $ttd->fetchAssoc()){//<--- $tid replaced by $ttd
  if($ttd_row['name']==$category){
    $tid=$ttd_row['tid'];//<----- There was clearly a conflict with this instance of $tid
    $result=db_query('SELECT entity_id FROM {field_data_field_boat_type} WHERE field_boat_type_tid=:tid',array(':tid'=> $tid));
    $eRows=$result->fetchAssoc();
    $eid=$eRows['entity_id'];
    $result=db_query('SELECT title FROM {node} WHERE nid=:nid',array(':nid'=>$eid));
    $eRows=$result->fetchAssoc();
    $titles[$eid]=$eRows['title'];
  }
}
print_r($titles);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.