CodeIgniter Forums

Full Version: Current Row
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]j4zzyh4ck3r[/eluser]
How to get current row when displaying a table data ?
Code:
<?php foreach ($result as $row): ?>
    <tr>
        <td>1</td>
        <td>&lt;?php echo sprintf("USd", $row->user_id); ?&gt;</td>
        <td>&lt;?php echo $row->user_username; ?&gt;</td>
        <td>&lt;?php echo $row->user_password; ?&gt;</td>
    </tr>
&lt;?php endforeach; ?&gt;

What code should I replace to '1' ? Thanks Smile

El Forum

[eluser]Johan André[/eluser]
Create a variable and increment it with every iteration.

El Forum

[eluser]j4zzyh4ck3r[/eluser]
[quote author="Johan André" date="1302702415"]Create a variable and increment it with every iteration.[/quote]

Is there any other solution other than iteration ?
I mean by using query object...

El Forum

[eluser]InsiteFX[/eluser]
Try this, not tested but would be something like that.
Code:
&lt;?php
$cnt = 1;
foreach ($result as $row): ?&gt;
    <tr>
        <td>&lt;?php echo $cnt;?&gt;</td>
        <td>&lt;?php echo sprintf("USd", $row->user_id); ?&gt;</td>
        <td>&lt;?php echo $row->user_username; ?&gt;</td>
        <td>&lt;?php echo $row->user_password; ?&gt;</td>
    </tr>
    &lt;?php $cnt++;?&gt;
&lt;?php endforeach; ?&gt;

InsiteFX

El Forum

[eluser]j4zzyh4ck3r[/eluser]
[quote author="InsiteFX" date="1302720136"]Try this, not tested but would be something like that.
Code:
&lt;?php
$cnt = 1;
foreach ($result as $row): ?&gt;
    <tr>
        <td>&lt;?php echo $cnt;?&gt;</td>
        <td>&lt;?php echo sprintf("USd", $row->user_id); ?&gt;</td>
        <td>&lt;?php echo $row->user_username; ?&gt;</td>
        <td>&lt;?php echo $row->user_password; ?&gt;</td>
    </tr>
    &lt;?php $cnt++;?&gt;
&lt;?php endforeach; ?&gt;

InsiteFX[/quote]

Ok... I got that, so we must use iteration, Thanks for your help Smile