Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tizer on
I'm editing some old code which has this query:
$result = db_query("SELECT entity_id FROM {field_data_field_category} WHERE field_category_tid = :cat", array(':cat' => $node->field_category['und'][0]['tid']));
I only want to return published nodes so tried to join with node table (code below) - but got this error:
DatabaseStatementBase::join()
$result = db_query("SELECT entity_id FROM {field_data_field_category} WHERE field_category_tid = :cat", array(':cat' => $node->field_category['und'][0]['tid']))
-> join('node', 'n', 'n.nid = entity_id')
-> condition('status', 1,'>');
$result = $query->execute();
Where am I going wrong - I'm pretty sure its to do with n.nid = entity_id - but am not sure how to change it.
Apologies if this is obvious - I'm pretty new to Drupal
Comments
Hi tizer,
Hi tizer,
You are mixing things up a little.
you can either use db_query() something like:
Or db_select() something like:
Thanks taslett :)
Thanks taslett :)
Yes - i can see now I was getting a bit mixed up (a bit!!!)... I've got to admit, there are so many reference sites with what seems like varying syntax - I am getting very mixed up (but getting there)
I got the first one working, thanks :)
But I am having problems with the second... don't answer though - I'll figure it out :)
Your condition
Your condition
is incorrect since status is either 0 (not published) or 1 (published) and you are testing to see if it greater than 1
correct, it should be ...
correct, it should be ...
'(Òvó)