发布
社区首页 >问答首页 >表的自动补全计数结果的php或javascript代码

表的自动补全计数结果的php或javascript代码
EN

Stack Overflow用户
提问于 2015-02-07 21:54:34
回答 3查看 222关注 0票数 0

日安。我的问题是如果我从一个表中查询。我想看看已经检索了多少行的结果。但它显示的是may表中的所有总行。我想知道结果的确切数字。

代码语言:javascript
代码运行次数:0
复制
<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>

EN

回答 3

Stack Overflow用户

发布于 2015-02-07 22:09:15

代码语言:javascript
代码运行次数:0
复制
<h1>(<?php echo mysql_num_rows($result); ?>)&nbsp&nbspRegistered Member</h1>

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

如果你想使用PDO,请阅读这个:How to replace MySQL functions with PDO?

票数 0
EN

Stack Overflow用户

发布于 2015-02-07 22:10:13

您不能使用客户端JavaScript访问数据库。

使用PHP,您可以通过在$result=mysql_query("SELECT * FROM tblreg where status = 'reg'");之后插入以下行来访问它

代码语言:javascript
代码运行次数:0
复制
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);

因此,您的代码将如下所示:

代码语言:javascript
代码运行次数:0
复制
<?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); ?>   
票数 0
EN

Stack Overflow用户

发布于 2015-02-07 22:11:02

代码语言:javascript
代码运行次数:0
复制
echo mysql_num_rows($result);

http://php.net/manual/en/function.mysql-num-rows.php

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28382972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档