如何在php中显示序号

时间:2014-04-12 09:43:25

标签: php

我想根据查询结果中显示的数据数量创建序号。 例如:

  • 1- david
  • 2- ahmad
  • 3-詹姆斯

<?
$class_id=$_GET['class_no'];

    $get_st=mysql_query("select * from students where calss_no='".$class_id."'");
    if($get_st != 0) {

        while($row=mysql_fetch_array($get_st)) {

             $st_no=$row['st_no'];
             $st_first_name=$row['st_first_name'];
             $st_last_name=$row['st_last_name'];
             $calss_no=$row['calss_no'];
             $super_no=$row['super_no'];

                echo"<a href=\"st_page.php?st_no=$st_no\">$st_first_name &nbsp;&nbsp;$st_last_name </a>"."<br>";        
        }

    } 
?>

1 个答案:

答案 0 :(得分:0)

我只是给出了这个概念。 这段代码没有结构化。

    <?php
    $class_id=$_GET['class_no'];

        $get_st=mysql_query("select * from students where calss_no='".$class_id."'");
        if($get_st != 0) {
         $sn = 1;
            while($row=mysql_fetch_array($get_st)) {

                 $st_no=$row['st_no'];
                 $st_first_name=$row['st_first_name'];
                 $st_last_name=$row['st_last_name'];
                 $calss_no=$row['calss_no'];
                 $super_no=$row['super_no'];

                    echo"<a href=\"st_page.php?st_no=$st_no\">$sn - $st_first_name &nbsp;&nbsp;$st_last_name </a>"."<br>"; 
                $sn++       
            }

        }


?>