开发者

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>
<? } ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜