您如何在Zend框架中编写以下查询?
SELECT * FROM table_name ORDER BY FIELD(field_name, 'Small','Medium','Large');
我只需要“Order by”部分:)
谢谢!
答案 0 :(得分:26)
这个怎么样:
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select();
$select->from('table_name')
->order(new Zend_Db_Expr("FIELD(field_name, 'Small','Medium','Large')"));
var_dump($select->assemble());
结果:
string 'SELECT `table_name`.* FROM `table_name` ORDER BY FIELD(field_name, 'Small','Medium','Large')' (length=92)
答案 1 :(得分:1)
$select->order(new Zend_Db_Expr('FIELD(field_name, 'Small','Medium','Large')'));
答案 2 :(得分:1)
我认为你应该这样做:
$db = Zend_Db::factory( ...options... );
$select = $db->select()
->from(table_name)
->order(new Zend_Db_Expr("FIELD(field_name, 'Small','Medium','Large')")));