$paymentIDs = Yii::app()->db->createCommand('SELECT payment_id FROM client_package WHERE package_id = :pid AND payment_id IS NOT NULL')->bindValue(':pid', $pid)->queryAll();
$total = Yii::app()->db->createCommand('SELECT count(*) FROM payment WHERE id IN ('.implode(",", $paymentIDs).') AND date BETWEEN \':mS\' AND \':mE\'')->bindValue(':mS', $monthStart)->bindValue(':mE', $monthEnd)->queryScalar();
The above is my code for a query. As you can see, I queried for payment_id(s) according to a certain criteria. And I now have a set of numbers.
When I execute the second query, it fails, throwing me an error
Array to String conversion
I have also tried this:
$total = Yii::app()->db->createCommand('SELECT count(*) FROM payment WHERE id IN ('.implode(",", $paymentIDs['payment_id']).') AND date BETWEEN \':mS\' AND \':mE\'')->bindValue(':mS', $monthStart)->bindValue(':mE', $monthEnd)->queryScalar();
Now, this gives me an error saying:
Undefined index: payment_id
Can someone please point out my mistake? Your help would be much appreciated.
Thanks.
\'around parameters. Also what values does parameters contains?var_dump($pid, $monthStart, $monthEnd, $paymentIDs);. Also consider using chinned version of Query Builder...->select()->where()...or CActiveRecord and CDbCriteria\'around the date? isn't it suppose to be likeBETWEEN '2015-05-01' AND '2015-06-01'? what$monthStartand$monthEndgive are: 2015-05-01 and 2015-06-01, yes, without quotes.'automatically to variables. If every parameter is of type string, than you have error somewhere else, try to figure out in what file and line error is thrown. (In error page$lineand$file)$paymentIDs(after print_r), I inserted the numbers into the implode, it's working fine, for example,... IN (2,7,8,13,14,17)..this would work fine. BUT not if I were to do... IN(implode(",", $paymentIDs))...