如何计算当前行数

时间:2013-04-22 07:35:16

标签: php mysql row

如何计算当前行?

如何计算php中当前的mysql行

我想计算当前没有排怎么能这样做请帮我解决这个问题谢谢 请看我的例子

这是代码

 $result1 = mysql_query("SELECT fees,name,id,grn,dateofjoin,class,rollno FROM admission where class '2013-04-01' order by class ASC");
                    while($row = mysql_fetch_array($result1))
                    {   



                // echo out the contents of each row into a table
                echo "<tr>";
                echo '<td>' . $row['id'] . '</td>';
                echo '<td>' . $row['name'] . '</td>';
                echo '<td>' . $row['dateofjoin'] . '</td>';
                echo '<td>' . $row['grn'] . '</td>';
                echo '<td>' . $row['class'] . '</td>';
                echo '<td>' . $row['rollno'] . '</td>';
                echo "</tr>"; 
    }

 echo "<tr>";
   echo '<td>Total</td>';
   echo '<td></td>';
   echo '<td></td>';
   echo '<td></td>';
   echo '<td></td>';
   echo '<td></td>';
   echo "</tr>";  



        // close table>
        echo "</table>";

现在显示如下

---------------------------------------------------
Id | Name |   Date      | GRN  | Class  | Roll No |
---------------------------------------------------
1  | abc  | 2013-04-01  | 192  | 10     | 42 
4  | xyz  | 2013-04-01  | 194  | 10     | 41
6  | ggg  | 2013-04-01  | 195  | 10     | 43 
9  | dfd  | 2013-04-01  | 196  | 10     | 44 
--------------------------------------------------
Total
--------------------------------------------------

我想要这样

---------------------------------------------------
Id | Name |   Date      | GRN  | Class  | Roll No |
---------------------------------------------------
1  | abc  | 2013-04-01  | 192  | 10     | 42 
4  | xyz  | 2013-04-01  | 194  | 10     | 41
6  | ggg  | 2013-04-01  | 195  | 10     | 43 
9  | dfd  | 2013-04-01  | 196  | 10     | 44 
--------------------------------------------------
Total                                    4 student
--------------------------------------------------

3 个答案:

答案 0 :(得分:3)

while($row = mysql_fetch_array之前,请执行以下操作:

 $rows = mysql_num_rows($result1);

更改最后一个

echo '<td></td>';

echo '<td>'.$total.' student</td>';

答案 1 :(得分:1)

echo '<td>'. mysql_num_rows($result1).'</td>';

注意 - 不推荐使用PHP的mysql扩展。使用http://php.net/manual/en/book.mysqli.php

答案 2 :(得分:0)

 $result1 = mysql_query("SELECT fees,name,id,grn,dateofjoin,class,rollno FROM admission where class '2013-04-01' order by class ASC");
 while($row = mysql_fetch_array($result1))
 {   
            // echo out the contents of each row into a table
            echo "<tr>";
            echo '<td>' . $row['id'] . '</td>';
            echo '<td>' . $row['name'] . '</td>';
            echo '<td>' . $row['dateofjoin'] . '</td>';
            echo '<td>' . $row['grn'] . '</td>';
            echo '<td>' . $row['class'] . '</td>';
            echo '<td>' . $row['rollno'] . '</td>';
            echo "</tr>"; 
}

  echo "<tr>";

  echo '<td>Total</td>';
  echo '<td colspan="5">'.$num=mysql_num_rows($result1).'</td>';
  echo "</tr>";  



    // close table
   echo "</table>";