Reputation: 31
I have code as shown below. What i want to do is either number each echo row, or get a total of how many rows are filtered according to the code below.
<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="****"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM members WHERE dealer= 'Panzer Protection'");
?>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FF0000"><center>
<? echo $rows['member_msisdn']; ?></td>
<td bgcolor="#FF0000"><center>
<? echo $rows['member_name']; ?></td>
<td bgcolor="#FF0000"><? echo $rows['dealer']; ?></td>
<td align="center" bgcolor="#FFFFFF"> </td>
<td align="center" bgcolor="#FFFFFF"><a href="control_clientinfo.php?member_id=
<? echo $rows['member_id']; ?>" class="update">Look Up</a></td>
</tr>
<?php
}
?>
So basically i need to count the rows displayed for the code
Upvotes: 0
Views: 96
Reputation: 63
You can use mysql_num_rows($result) to get the total number of rows and use a simple count variable in the while-loop to get the number of each row.
Upvotes: 0
Reputation: 30488
You can get the number of rows using mysql_num_rows()
function
echo mysql_num_rows($result);
As a side note Stop using mysql_*
because its deprecated start using Mysqli
OR PDO
.
Upvotes: 1