how to select query from drupal 7

1k Views Asked by At

i have this query on drupal 6

$catq=' ( SELECT term_node.nid as node_id FROM {term_node} WHERE tid='.$catint.') as cat, '

i have upgrade it like this

$query=db_select('term_node');
                    ->addfield('term_node', 'nid', 'node');
                    ->field('term_node', 'node' ); 
                    ->condition('term_node.tid', = , $catint);
                $cat=$query->addfield($query, 'cat');

is it wrong?

1

There are 1 best solutions below

2
On

You are doing it wrong. The right syntax for query - keeping your data will be:

$query = db_select('term_node', 't')
            ->fields('t')
            ->condition('term_node.tid', $catint, '=')
            ->execute();
          $logo = $query->fetchAll();

But in drupal 7 there is no table term_node, probably you need 'taxonomy_index'.