Good day. my problem is if i query from a table. i want to see the result of how many row has been retrieve. but it was displaying all the total rows in may table. i want the exactly number of the result.
<div id="lala">
<?php $query = "SELECT COUNT(*) AS total FROM tblreg where status='reg'";
$result = mysql_query($query);
$values = mysql_fetch_assoc($result);
$num_rows = $values['total']; ?>
<h1>(<?php echo $num_rows ?>)  Registered Member</h1>
</div>
<div id="formdesign"><input type="text" name="filter" value="" id="filter" placeholder="Search " autocomplete="off" /> </div>
<table id="resultTable" data-responsive="table">
<thead>
<tr>
<th>Username</th>
<th>Fullname</th>
<th>Course</th>
<th>Year Graduated</th>
<th>Email</th>
<th>Send Email</th>
<th>Delete</th>
</tr>
</thead>
<?php
include("dbcon.php");
$result=mysql_query("SELECT * FROM tblreg where status = 'reg'");
while($test = mysql_fetch_array($result))
{
$id = $test['reg_id'];
echo "<tr align='center'>";
echo"<td>" .$test['username']."</td>";
echo"<td>" .$test['fullname']."</td>";
echo"<td>" .$test['course']."</td>";
echo"<td>" .$test['year_grad']."</td>";
echo"<td>" .$test['email']."</td>";
echo"<td> <a href='email.php?id=$id' rel='facebox[.bolder]' ><img src='icons/e_mail.png'></a>";
echo"<td> <a href='deleteregmember.php?id=$id' onclick='return confirm_delete()'><img src='icons/list-error.png'></a>";
echo "</tr>";
}
mysql_close();
?>
</tr>
<h1>(<?php echo mysql_num_rows($result); ?>)  Registered Member</h1>
That should display the amount of rows fetched from the database.
I you want to use PDO please read this: How to replace MySQL functions with PDO?
You can't access the database with Client-Side JavaScript.
With PHP you can access it by inserting this line after $result=mysql_query("SELECT * FROM tblreg where status = 'reg'");
:
echo mysql_num_rows($result);
This way you will get the rows affected by the query.
On the other hand, use mysqli_* or PDO functions, since mysql_* functions are outdated and depracted.
You can find the official documentations on PHP's site:
mysql_num_rows: http://php.net/manual/en/function.mysql-num-rows.php
mysqli_* functions: http://php.net/manual/en/book.mysqli.php
PDO : http://php.net/manual/en/book.pdo.php
UPDATE: In your code just make the $num_rows variable equal to mysql_num_rows($result);
So your code will look something like this:
<?php $query = "SELECT COUNT(*) AS total FROM tblreg where status='reg'";
$result = mysql_query($query);
$values = mysql_fetch_assoc($result);
$num_rows = mysql_num_rows($result); ?>
echo mysql_num_rows($result);