日安。我的问题是如果我从一个表中查询。我想看看已经检索了多少行的结果。但它显示的是may表中的所有总行。我想知道结果的确切数字。
<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>
发布于 2015-02-07 22:09:15
<h1>(<?php echo mysql_num_rows($result); ?>)  Registered Member</h1>
这应该会显示从数据库获取的行数。
如果你想使用PDO,请阅读这个:How to replace MySQL functions with PDO?
发布于 2015-02-07 22:10:13
您不能使用客户端JavaScript访问数据库。
使用PHP,您可以通过在$result=mysql_query("SELECT * FROM tblreg where status = 'reg'");
之后插入以下行来访问它
echo mysql_num_rows($result);
这样,您将获得受查询影响的行。
另一方面,使用mysqli_*或PDO函数,因为mysql_*函数已经过时和过时了。
你可以在PHP的网站上找到官方文档:
mysql_num_rows:http://php.net/manual/en/function.mysql-num-rows.php
mysqli_*函数:http://php.net/manual/en/book.mysqli.php
PDO:http://php.net/manual/en/book.pdo.php
更新:代码中的只需使$num_rows变量等于mysql_num_rows($result);
因此,您的代码将如下所示:
<?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); ?>
发布于 2015-02-07 22:11:02
echo mysql_num_rows($result);
https://stackoverflow.com/questions/28382972
复制相似问题