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?