2012-02-03 96 views
0

是否有另一种方法来计算查询返回的行数。下面的代码返回1,即使没有返回结果(我正在处理ZEND)。函数计算zend中的查询结果

$this->view->overdue_query = $overdue_query->fetchAll(); 
/*Get overdue count */ 
$this->view->overdue_count = count($overdue_query); 
+0

是否有像mysql_num_rows这样的函数? – Micheal 2012-02-03 20:06:43

+0

我很好奇var_dump($ overdue_query)返回的输出。我想你应该从fetchAll()获得一个普通的数组。你可以请张贴吗? – drew010 2012-02-03 20:40:34

+0

@ drew010 fetchAll()返回一个Zend_Db_Table_Rows对象。您可以使用 - > toArray()将其转换为数组。 – Iznogood 2012-02-03 21:53:34

回答

0
$this->view->overdue_query = $overdue_query->fetchAll(); 
/*Get overdue count */ 
$this->view->overdue_count = count($overdue_query);//you are doing count on 
//your query and not the result of fetchAll 

它应该是代替

$this->view->overdue_query = $overdue_query->fetchAll(); 
/*Get overdue count */ 
$this->view->overdue_count = count($this->view->overdue_query); 

//unless you're getting overdue_count in your view then you would do : 
$count = count($this->overdue_query); 
0

据我所知,这应该工作,我一直这样做。

$results = $overdue_query->fetchAll(); 
echo count($results); 

如果它在你的代码中没有其他的东西是错的,那么它很难说。 也尝试toArray()来查看它是否改变任何东西。

$results = $overdue_query->fetchAll()->toArray(); 
echo count($results); 

Documentation

0

我与MMC,您正试图计算错误的事情达成一致。 count($ this-> view-> overdue_query);应该做的伎俩。