Specify Serial No. in mysql while function
while ($one = mysql_fetch_array($two)) {
<td>Want Serial No Here</td>
<td><?=$something['something']?></td>
}
I want to开发者_StackOverflow autonumber Serial No. .. is it possible?
I have the impression that you are trying to generate a consecutive number for each row:
<?php
$count = 0;
while($row = mysql_fetch_assoc($res)){
$count++;
echo '<tr><td>' . $count . '</td><td>' . htmlspecialchars($row['name']) . '</td></tr>';
}
MySQL
does not support rownum
/ row_number
natively.
You could emulate it using session variables:
SET @r := 0;
SELECT @r := @r + 1 AS rownum, t.*
FROM mytable
ORDER BY
myfield
, or better, just use a PHP
variable:
<?
$i = 0;
while ($row = mysql_fetch_assoc($res)) { ?>
<td><?= ++$i ?></td>
<td><?=$row['serial_no']?></td>
<? } ?>
精彩评论