doutidi5037
doutidi5037
2013-04-01 08:01

如何改变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 dongping4461 8年前

    Change $query2 as below

    $query2="SELECT DISTINCT stud_no FROM fees_master ORDER BY stud_no  ;";
    
    点赞 评论 复制链接分享