user3210341
user3210341

Reputation: 77

drupal 7 sort query results with db_query syntax error

I want to get all the comments for certain node, i use db_query. that works fine. But i can not order it by created time. I got PHP Parse error: syntax error, unexpected T_STRING

$results = db_query('SELECT c.nid,c.name, c.uid, c.subject, c.created FROM {comment} c WHERE c.nid = :nid', array(':nid' => $node_id) ORDER By c.created DESC);
foreach ($results as $result) {

}

I found that can be done with db_select, but i would like to know how to do it with db_query?

Upvotes: 0

Views: 802

Answers (1)

Tom  Tang
Tom Tang

Reputation: 96

I think your may want to try following code:

$results = db_query('SELECT c.nid,c.name, c.uid, c.subject, c.created 
                     FROM {comment} c 
                     WHERE c.nid = :nid 
                     ORDER By c.created 
                     DESC',
array(':nid' => $node_id));
foreach ($results as $result) {

}

Upvotes: 1

Related Questions