public function actionCarireport() {
$_POST['Penjualan']['dari_tgl'] = date('Y-m-d', strtotime($_POST['Penjualan']['dari_tgl']));
$_POST['Penjualan']['sampai_tgl'] = date('Y-m-d', strtotime($_POST['Penjualan']['sampai_tgl']));
$command = Yii::app()->db->createCommand('SELECT id_penjualan FROM penjualan WHERE tgl_penjualan >= :dari_tgl AND tgl_penjualan <= :sampai_tgl');
$command->bindValues(array(':dari_tgl' => $_POST['Penjualan']['dari_tgl'], ':sampai_tgl' => $_POST['Penjualan']['sampai_tgl']));
$report = Penjualan::model()->findByAttributes(array('id_penjualan' => $command->queryScalar()));
echo $report->total;
}
when I tried to run this searching application, it’s work but it’s only show 1 result which is the last inserted one, instead of showing the whole results that match with the date.
anyone can tell me what’s wrong with my codes and how to solve it? thanks in advance
thanks well, I think it’s just the same with mine. Because it give me the same result. Anyway, I found the problem already, and I think this is the most stupid question I ever asked here
the first code give me only 1 result because it’s find not findAll. and my new code, it’s show me the whole results that match with the inserted date now. sorry for my stupidity
The improvement is that you’re only running a single database query rather than two. Yours was initially running a query to get a list of ID’s that matched the conditions, then running a query to get the records with those ID’s.
Using the CDbCriteria object is also far more readable in this case, so should be much more maintainable.
I’ve check it already that this code able to pick the data . but, it won’t give any result and only give me a blank white page instead. can you help me with this? thanks in advance