php - Yii, querying gives array to string error -
$paymentids = yii::app()->db->createcommand('select payment_id client_package package_id = :pid , payment_id not null')->bindvalue(':pid', $pid)->queryall(); $total = yii::app()->db->createcommand('select count(*) payment id in ('.implode(",", $paymentids).') , date between \':ms\' , \':me\'')->bindvalue(':ms', $monthstart)->bindvalue(':me', $monthend)->queryscalar();
the above code query. can see, queried payment_id
(s) according criteria. , have set of numbers.
when execute second query, fails, throwing me error
array string conversion
i have tried this:
$total = yii::app()->db->createcommand('select count(*) payment id in ('.implode(",", $paymentids['payment_id']).') , date between \':ms\' , \':me\'')->bindvalue(':ms', $monthstart)->bindvalue(':me', $monthend)->queryscalar();
now, gives me error saying:
undefined index: payment_id
can please point out mistake? appreciated.
thanks.
the result of first query, $paymentids
, array of arrays (or plain objects, i'm not sure). can try inspecting in ide or use var_dump
see structure. can use listdata
method of chtml class closer want, this:
$ids = chtml::listdata($paymentids, 'payment_id', 'payment_id');
that flatten array array of strings. then...
implode(",", $ids)
...will give result want.
Comments
Post a Comment