我遇到了query
的问题,导致以下错误
PHP Fatal error: Call to a member function result() on boolean on line 200
我对其他queries
没有任何问题,但在此问题上,我必须在query
内执行query
,具体如下:
$this->load->helper('date');
$datestring = "%Y-%m-%d";
$time = strtotime('yesterday');
$date= mdate($datestring, $time);
$db = $this->load->database('macs', TRUE);
$query = $db->query("SELECT TOP 1 TEMP1.USER AS PACKER, Count(TEMP1.[ORDER]) AS ORDERS FROM (SELECT AUDIT.USER, AUDIT.[ORDER] FROM AUDIT WHERE AUDIT.DATE > '$date' AND (AUDIT.TYPE='I11' Or AUDIT.TYPE =' 11') GROUP BY AUDIT.DATE, AUDIT.TYPE, AUDIT.USER, AUDIT.[ORDER]) AS TEMP1 GROUP BY TEMP1.USER ORDER BY Count(TEMP1.[ORDER]) DESC");
return $query->result();
$macsdb->close();
这在访问中正常工作(以上是访问查询的转换)。当删除引用query
的任何内容时,USER
开始工作(但不正确)。可能导致这种情况的原因是什么?
答案 0 :(得分:2)
MySQL不支持TOP
子句
如果你想获得TOP 1记录,你可以使用这样的查询
SELECT * FROM table_name ORDER BY field_name DESC LIMIT 1