display row number

I have this:


$top=new CActiveDataProvider('ritmo',array(


    'criteria'=>array(


        'select'=>'idritmo,count(*) top,artist,title',


        'join'=>'inner join encomenda_linha on (t.idritmo=encomenda_linha.style)',


		'group'=>'t.idritmo',


		'order'=>'top DESC'  


    ),


    ))

How to include the row number on select??

what do you mean with row number?

in oracle you have ROWNUM function and mysql?

I use this to create a top10 rank

do you need that number in your grid?

http://blog.mbischof.de/cgridcolumn

Yes i do.No mysql function to return this?

It’s probably best to do this in your application code because there’s no built in MySQL implementation. You could use something like this though:

http://jimlife.wordpress.com/2008/09/09/displaying-row-number-rownum-in-mysql/

Ok it’s cool but how to do in the CActiveDataProvider?

How is the row number going to be used?

For most uses, you should really just calculate it as you build the output. The row number is part of the view because it’s not tied to a specific row of the database; it’s purely for display purposes.

i have this output.Instead of foreach can i do a normal for to have a index??


<div class="top10-lista-container">

            <ul>

                <?php foreach ($top->data as $ritmotop) { ?>

                <li>

                    <div class="posicao"></div>

                    <div class="descricao">

                        <p class="artist"><?php echo $ritmotop->artist; ?></p>

                    </div>

                </li>

               <?php  } ?>

            </ul>

        </div>

I’d do it like this:




            <ul>

                <? $rowNum = 1; ?>

                <? foreach ($top->data as $ritmotop): ?>

                <li>

                    <div class="posicao"></div>

                    <div class="descricao">

                        <p class="artist"><?= $ritmotop->artist; ?></p>

                    </div>

                    <? $rowNum++; ?>

                </li>

               <? endforeach; ?>

            </ul>



Of course, only use the short tags if they’re available on your target platforms.

You could try like this example:


SELECT  t.id, 

        t.name, 

        t.desc,

        @curRow := @curRow + 1 AS row_number

FROM    table t

JOIN    (SELECT @curRow := 0) r;



I saw this on stackoverflow :)

thank you