0

如何计算当前行数?

如何在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
--------------------------------------------------
4

3 回答 3

3

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

 $rows = mysql_num_rows($result1);

改变最后一个

echo '<td></td>';

echo '<td>'.$total.' student</td>';
于 2013-04-22T07:36:16.603 回答
1

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

注意 - PHP 的 mysql 扩展已被弃用。使用http://php.net/manual/en/book.mysqli.php

于 2013-04-22T07:37:27.897 回答
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>";
于 2013-04-22T07:42:48.063 回答