Welcome Guest, Not a member yet? Register   Sign In
Current Row
#1

[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
#2

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

[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...
#4

[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
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB