tags:

views:

37

answers:

2

Hi!

My $num_rows echos the total row count but I want the current row number.

<?php
$result = mysql_query('SELECT * FROM texts ORDER BY id desc');
while($row = mysql_fetch_array($result)){
$num_rows = mysql_num_rows($result);
?>
<tr class="alt">
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['title']; ?></td>
    <td><a href="<?php echo $row['orginal']; ?>">Original</a></td>
    <td><a href="#">@English</a></td>
    <td><a href="#"><?php echo $num_rows; ?></a></td>
</tr>
<?php
}
?>

Thank you :)

+4  A: 

why you should not use a increment variable to count the loop turns inside while?

$tmpCount = 1;
while() {

   $tmpCount ++;
}

Is this helpful to you? or are you expecting the physical row number of from database?

Muneer
Thank you, dident think of that :D
Victor
A: 

If you want to just number the rows returned by the query (instead of using the actual ID - $row['id'] presumably), you can just increment a number with each row:

$num_rows = 0;

while ($row = mysql_fetch_array($result)){
  $num_rows++;
  // ...
Chris Smith
The thing is that if I remove one row then the count will be wrong with $_row['id']Thanks anyway :)
Victor