javascript - 用于自动完成表格计数结果的 php 或 javascript 代码

标签 javascript php jquery mysql

美好的一天。我的问题是如果我从表中查询。我想查看已检索多少行的结果。但它显示了五月表中的所有总行数。我想要结果的确切数字。

<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 ?>)&nbsp&nbspRegistered 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); ?>)&nbsp&nbspRegistered Member</h1>

这应该显示从数据库获取的行数。

如果您想使用 PDO,请阅读以下内容: How to replace MySQL functions with PDO?

关于javascript - 用于自动完成表格计数结果的 php 或 javascript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28382972/

相关文章:

javascript - encodeForHTMLAttribute 与 encodeForJavaScript

php - PhpMyAdmin 中的培训需求分析数据库 - 难以在我的数据库中存储用户特定的 radio 答案

Phpspreadsheet - 时间单元格检索为 float

php - 检查 session 是否存在(Nginx)

jquery 将跨度集中在图像悬停上(因为它可能是内联的?)

javascript - 使用 sortable.js 时如何在 php 中返回一个新数组

javascript - Nodejs Passport - 使用多个谷歌策略

javascript - 动态渲染 onclick document.location

javascript - 如何将 networkx 图导出到 javascript?

javascript - 更改 JavaScript 源