简体   繁体   English

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

[英]How to alter number of repetitions in while loop?

i have one php page in which I have two loops in place. 我有一个PHP页面,其中有两个循环。 this loop is used to retrieve data from database column and print in the form of a row group by stud_no column. 此循环用于从数据库列中检索数据,并按stud_no列以行组的形式打印。

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 http://i.stack.imgur.com/qLvE5.png

please help. 请帮忙。 I want to print each distinct line only once. 我只想将每个不同的行打印一次。

如下更改$ query2

$query2="SELECT DISTINCT stud_no FROM fees_master ORDER BY stud_no  ;";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM