doutidi5037 2013-04-01 08:01
浏览 52
已采纳

如何改变while循环中的重复次数?

i have one php page in which I have two loops in place. this loop is used to retrieve data from database column and print in the form of a row group by stud_no column.

here is a code:

<?php  
     $link=mysql_connect("localhost","xyz","toor") or die("Cannot Connect to the database!");
     mysql_select_db("dbase",$link) or die ("Cannot select the database!");
     $query2="SELECT stud_no FROM fees_master ORDER BY stud_no  ;";
     $resource2=mysql_query($query2,$link);

     $i=1;
     while($res=mysql_fetch_array($resource2)) {
        $lsd=$res[0];
        $query="SELECT stud_no,inst_amt FROM fees_master WHERE stud_no LIKE $lsd ;";

        $resource=mysql_query($query,$link);
        echo"<table align=\"center\" border=\"0.5\"> <tr>";

        while($result=mysql_fetch_array($resource)){ 

           echo "<td>".$i."</td>,";
           echo "<td>".$result[0].",</td>";
           echo "<td>".$result[1].",</td>,";
          if($result[0]!==$lsd)
          {
              echo"</tr></table>";
              break;
          }
        } 
}
?>  

after running this code I am getting this output:

http://i.stack.imgur.com/qLvE5.png

please help. I want to print each distinct line only once.

  • 写回答

1条回答 默认 最新

  • dongping4461 2013-04-01 08:10
    关注

    Change $query2 as below

    $query2="SELECT DISTINCT stud_no FROM fees_master ORDER BY stud_no  ;";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题