Answer the question
In order to leave comments, you need to log in
Working with a database in Drupal 7?
Hello.
You need to redo the database query to display tags according to the dictionary with the number of nodes on Drupal 7, here is the query itself
db_query("SELECT tid, name, (SELECT COUNT(*) FROM {taxonomy_index} ti LEFT JOIN {node} n ON ti.nid = n.nid WHERE ti.tid = td.tid AND n.status = 1) node_count FROM {taxonomy_term_data} td WHERE vid = :vid ORDER BY weight", array(':vid' => 3));
$query = db_select('node', 'n');
$query->innerJoin('users', 'u', 'n.uid = u.uid');
$query->fields('n', array('title'));
$query->fields('u', array('name'));
$nodes = $query->execute()->fetchAll();
Answer the question
In order to leave comments, you need to log in
$query = db_select('taxonomy_term_data', 'td');
$query->fields('td', array('tid', 'name'));
$query->condition('td.vid', 3);
$query->addExpression("(SELECT COUNT(*) FROM {taxonomy_index} ti LEFT JOIN {node} n ON ti.nid = n.nid WHERE ti.tid = td.tid AND n.status = 1)", 'node_count');
$terms = $query->execute()->fetchAll();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question