0
SELECT * FROM abc
WHERE xyz LIKE $x OR xyz LIKE $y OR xyz LIKE $z
ORDER BY ((xyz LIKE $x) + (xyz LIKE $y) + (xyz LIKE $z)) DESC

我几乎可以编写查询,ordey by asd desc但是如何在 codeigniter 中编写这个复杂的查询?

4

2 回答 2

0

您可以像拥有它一样用普通的 sql 编写它并使用该db->query方法执行它。

$sql = 'SELECT * FROM abc
WHERE xyz LIKE ? OR xyz LIKE ? OR xyz LIKE ?
ORDER BY ((xyz LIKE ?) + (xyz LIKE ?) + (xyz LIKE ?)) DESC'

$this->db->query($sql, array($x, $y, $z, $x, $y, $z));

http://codeigniter.com/user_guide/database/queries.html查询绑定解释了?

于 2012-08-27T18:01:56.437 回答
0

也许你应该检查ActiveRecord

$this->db->
   from("abc")->
   or_like("xyz",$x)->
   or_like(...)->
   order_by(...);
$result = $this->db->result_array();
于 2012-08-27T18:28:36.660 回答