1
您好我已经写了一个有条件order by子句的MySQL语句,您可以在下面的示例中看到。Drupal db_select PDO声明:ORDER BY CASE
的MySQL实例:
SELECT
title,
description
FROM books
WHERE
title LIKE "%keyword%" OR description LIKE "%keyword%"
ORDER BY
CASE
WHEN title LIKE "%keyword%"
THEN 1
ELSE 2
END
我现在想重新使用它的PDO风格db_select()函数在Drupal这一说法。但是在编写ORDER BY子句时我遇到了困难。
Drupal的例子:
$node_select = db_select('node', 'n');
$node_select->fields('n', array('title', 'description'));
$node_select->condition(
db_or()->condition('n.title', '%'.$keyword.'%', 'LIKE')
->condition('n.description', '%'.$keyword.'%', 'LIKE')
);
$node_select->order();
任何人都可以点我你会怎么写ORDER BY部分朝着正确的方向?
真棒,它做了谢谢。 –
使用addExpression和countQuery我遇到了一个问题,但它是一个简单的修复,一旦你阅读这个http://drupal.stackexchange.com/questions/19032/d7-bug-with-db-select-addexpression-and-having -条件 –