user2260431
user2260431

Reputation: 75

how to count current number of rows

how to count current rows?

how to count current rows of mysql in php

i want to count current no of row how can i do this please help me to fix this issue thanks please see my example

this is code

 $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>";

and now showing like this

---------------------------------------------------
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
--------------------------------------------------

and i want like this

---------------------------------------------------
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
--------------------------------------------------

Upvotes: 0

Views: 169

Answers (3)

Suhel Meman
Suhel Meman

Reputation: 3852

 $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>";

Upvotes: 0

Osiris
Osiris

Reputation: 4185

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

Note - PHP's mysql extension is deprecated. Use http://php.net/manual/en/book.mysqli.php

Upvotes: 1

Tim Groeneveld
Tim Groeneveld

Reputation: 9019

Before while($row = mysql_fetch_array, do this:

 $rows = mysql_num_rows($result1);

Change the last

echo '<td></td>';

to

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

Upvotes: 3

Related Questions