In Drupal v7.22 I'm trying to order the query below for a custom module but I cannot seem to find documentation that fits this query.
$sql = "SELECT field1, field2 FROM {tablename} WHERE field3 = :var1 AND field4 = :var2";
$result = db_query($sql, array(':var1' => $var1, ':var2' => $var2));
$num = $result->rowCount();
if ($num != null) {
foreach($result as $line) {
// Do something
}
}
I've found details on 'orderBy' but only with examples as below which are not in the same format as my query. Any help would be appreciated.
$query->groupBy("thread.sid");
$query->having("MAX(comment.created)");
$query->orderBy("comment.created", "DESC");
$result = $query->execute();