hi all pls tell me how to get the rcord index with results return by CDBCriteria.
I want to do something like this:
SELECT @rank:=@rank+1 AS rank, fruit, amount
ORDER BY amount DESC
$criteria = new CDbCriteria;
$criteria->params = "SET @rownum := 0,";
$criteria->select = ‘@rownum := @rownum + 1 AS rank,t.id,t.business_name,bc.category_name’;
$criteria->join .= ’ INNER JOIN business_categories bc ON t.business_category_id = bc.id’;
but rank is always empty.
Also tried with : $criteria->index=‘rank’;
But its always empty.
I suspect the alias. Did you try to use a regular column as index? And did you also define a public property ‘rank’ in your model?
Apart from that: Even if it worked, your code seem to return a 0 based index anyway. Or am i missing something? Never worked with variables in MySQL.
Thnx for the quick attention.
The generic SQL I posted is working properly.
I tried using regular column as index but no luck : $criteria->index=‘id’;
Yes I defined a public property ‘rank’ in my model.
What I need is record ranking to use with ‘alphapager’ extension:
But no need to worry about the extension if there’s any possible way of getting the record ranking with CDbCriteria.