[support] What's wrong with this query?

Metzler, David metzlerd at evergreen.edu
Fri Jul 6 20:57:08 UTC 2012


You need to transition  between a query builder object and the result
set object. 

The query builder object and the result set aren't the object as your
code assumes.. 

 

I'd rewrite it this way: 

 

  $result = db_select('taxonomy_term_data', 't')
     ->addField('t', 'tid');
     ->condition('t.vid', $vids, 'IN')
     ->condition(db_or()->condition('t.description', "%$keys%", 'LIKE')

     ->condition('t.name', "%$keys%", 'LIKE'))
     ->execute();

  $found = NULL;
  foreach ($result as $row) {
    $output .= print_r($row, true);
  }

 

 

But if you need other conditional logic around this make the last line
be: 

 

$result = $result->execute(); 

 

________________________________

From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Ms. Nancy Wichmann
Sent: Friday, July 06, 2012 1:44 PM
To: support drupal
Subject: [support] What's wrong with this query?

 

  $result = db_select('taxonomy_term_data', 't');
  $result->addField('t', 'tid');
  $result->condition('t.vid', $vids, 'IN')
    ->condition(db_or()->condition('t.description', "%$keys%",
'LIKE')->condition('t.name', "%$keys%", 'LIKE'))
    ;
  $result->execute();

  $found = NULL;
  foreach ($result as $row) {
    $output .= print_r($row, true);
  }
The Devel query log shows the query properly built. I copied the query
from the log into PhpMyAdmin and it gets one row. But my code shows
nothing fetched.

 

Nancy

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20120706/57848c36/attachment.html 


More information about the support mailing list