Naeem Marzu Naeem Marzu - 27 days ago 4x
Javascript Question

createCommand undefined js

I've looked everywhere and couldn't find an answer for me i've create command and its works fine but i get undefined

public function actionTotal($id)

$query1 = new Query;
$query1 ->select('sum(price) price')
->where('patient_id=:id', array(':id'=>$id));
$command1 = $query1->createCommand();
$price = $command1->queryAll();
echo Json::encode($price);


my jQuery Code :

var service_id =$(this).val();
$.get('index.php?r=receipts/total',{ id : service_id},function(data)
var data=$.parseJSON(data);
$('#receipts-price').attr('value',data.price); // here i got nothing
alert(data.price); // here i got undefined

inspect with Firebug


You need queryScalar for obtain the price only

$price = $command1->queryScalar();  

queryAll() return all the models .. query scalar the first column of the firts row value only

try referring to data[0]