zipzapduo
(Zipzapduo)
July 17, 2012, 9:02pm
1
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??
mbi
(mbi)
July 17, 2012, 9:08pm
2
what do you mean with row number?
zipzapduo
(Zipzapduo)
July 17, 2012, 9:55pm
3
in oracle you have ROWNUM function and mysql?
I use this to create a top10 rank
mbi
(mbi)
July 18, 2012, 9:01am
4
do you need that number in your grid?
http://blog.mbischof.de/cgridcolumn
zipzapduo
(Zipzapduo)
July 18, 2012, 9:08am
5
Yes i do.No mysql function to return this?
Keith
(Kburton)
July 18, 2012, 10:49am
6
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/
zipzapduo
(Zipzapduo)
July 18, 2012, 10:51am
7
Ok it’s cool but how to do in the CActiveDataProvider?
Keith
(Kburton)
July 18, 2012, 11:07am
8
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.
zipzapduo
(Zipzapduo)
July 18, 2012, 11:39am
9
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>
Keith
(Kburton)
July 18, 2012, 11:52am
10
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.
Gildo
(MasterG)
July 18, 2012, 12:21pm
11
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