2012-02-03 3 views
0

クエリによって返された行を数えない方法がありますか?返される結果がないのに、次のコードは1を返します。zendでクエリ結果を数える関数

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

mysql_num_rowsのような機能はありますか? – Micheal

+0

'var_dump($ overdue_query)'の出力が何を返すのか不思議です。私はfetchAll()からプレーンな配列を得るべきだと思います。投稿していただけますか? – drew010

+0

@ drew010 fetchAll()はZend_Db_Table_Rowsオブジェクトを返します。 - > toArray()を使用して配列にキャスト/変換できます。 – Iznogood

答えて

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 

それは私はあなたが間違ったことをカウントしようとしているMMCに同意する代わりに

$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

私が知っている限り、これはいつもやっているはずです。

もしあなたのコードの中に他の何かが間違っていると言うのは間違いです。 また、何か変更があるかどうかを調べるにはtoArray()を試してください。

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

Documentation

0

でなければなりません。 件数($ this-> view-> overdue_query);トリックを行う必要があります。