I have sql code like this
SELECT MAX(Q_number) as Q FROM customers
how to use
$criteria = new CDbCriteria;
query data?
I have sql code like this
SELECT MAX(Q_number) as Q FROM customers
how to use
$criteria = new CDbCriteria;
query data?
Hi,
Check this one
$criteria = new CDbCriteria;
$criteria->select = 'MAX(Q_number)';
$provider = new CActiveDataProvider('customers', array(
'criteria'=>$criteria,));
Thank. how to return value to variable.
return $provider->getData('MAX');
but I get error
Array to string conversion
Like this:
$criteria = new CDbCriteria;
$criteria->select = 'MAX(Q_number) AS `max`';
$provider = new CActiveDataProvider('customers', array(
'criteria'=>$criteria,));
// access it with $model->max or $provider->getData('max'); (<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />)
But make sure your model class has a public property $max:
public $max;
This worked to return a single value
$sql="select MAX(Q_number) as maxL from customers";
$command=$connection->createCommand($sql);
$data = $command->queryRow();
$maxL = $data['maxL'];
return $maxL;
Thank you.
Yes you could this either command query or dataprovider
if you have many max (for example using group by) then you could use
foreach($provider->getData() as $data) {
$max = $data['maxL'] //or maybe $data->maxL
}