1

I'm trying to execute the following query but when I append the 'n.nid = "node/" + ua.source' condition I'm getting an error page:

        $query = db_select('node', 'n')->extend('PagerDefault');
        $query->join('url_alias', 'ua', 'n.nid = "node/" + ua.source');
        $nids = $query
            ->fields('n', array('nid', 'sticky', 'created'))
            ->condition('type', 'news')
            ->condition('status', 1)
            ->orderBy('sticky', 'DESC')
            ->orderBy('created', 'DESC')
            ->limit(3)
            ->addTag('node_access')
            ->execute()
            ->fetchCol();

Any suggestions to resolve this?

  • 2
    Basic PHP questions are not on-topic on this website. It should be easy to find the php syntax for variables and string concatenation on the internet, but right here isn't the place for it. :) – Letharion Mar 2 '15 at 19:22
4

There is a small changes in code. I think it will help you.

$query = db_select('node', 'n')->extend('PagerDefault');
        $query->join('url_alias', 'ua', "ua.source = CONCAT('node/', n.nid)" );
        $nids = $query
            ->fields('n', array('nid', 'sticky', 'created'))
            ->condition('type', 'news')
            ->condition('status', 1)
            ->orderBy('sticky', 'DESC')
            ->orderBy('created', 'DESC')
            ->limit(3)
            ->addTag('node_access')
            ->execute()
            ->fetchCol();

For more info check

Not the answer you're looking for? Browse other questions tagged or ask your own question.