分页计数查询的mysql问题 [英] mysql problem with count query in pagination

查看:325
本文介绍了分页计数查询的mysql问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GROUP BY来获取数据,但是现在我在代码中添加了分页功能,并且它需要COUNT查询才能计算table ..中的行数.所以我也在该COUNT查询中使用了GROUP BY ..但不是工作正常..任何人都可以帮我吗?这是我的代码

I am fetching my data using GROUP BY but now I added pagination in my code and it require COUNT query to count the number of rows in table.so i have also used GROUP BY in that COUNT query .. but it is not working properly.. can anyone help me out?? here is my code

$query ="SELECT COUNT(*)
         FROM import
         {$WHERE} GROUP BY mobno,telecaller";
$result = mysql_query($query);
$total_records = mysql_result($result,0);
$total_pages = ceil($total_records / $records_per_page);
//Set page number
$pageno = (isset($_GET['pageno'])) ? intval($_GET['pageno']) : 1;
$pageno = min(max($pageno, 1), $total_pages);
$LIMITSTART = ($pageno - 1) * $records_per_page;
$query = "SELECT date, mobno, city, state, type, telecaller
          FROM import
          {$WHERE}
          GROUP BY mobno,telecaller
          ORDER BY date DESC
          LIMIT  $LIMITSTART, $records_per_page";
$result = mysql_query($query);
print"<div id='print'>";
echo"<center>List of Mobile Numbers for Telecaller <font color='#FF00FF'><U> $_POST[select]\r</U> </font> <center> <br/>";
echo "<table border='1' cellspacing='1' cellpadding='6'>
<tr bgcolor='#82CAFF'>
<th>Sr.No</th>
<th>Date</th>
<th>Mobile No</th>
<th>City</th>
<th>State</th>
<th>Type</th>
<th>CIExe.</th>
</tr>";
//if(isset($_POST['submit']))
//{
$srno1=0;
while($row=mysql_fetch_array($result))
{
    $srno1=$srno1+1;
echo "<tr>";
echo "<td>". $srno1. "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>".  $row['mobno'] ."</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['telecaller'] . "</td>";
echo "</tr>";
}
echo"</table>";



谢谢..



THANKS IN ADVANCE..

推荐答案

query ="SELECT COUNT(*) 从进口 {
query ="SELECT COUNT(*) FROM import {


WHERE} GROUP BY mobno,telecaller;
WHERE} GROUP BY mobno,telecaller";


result = mysql_query(
result = mysql_query(


这篇关于分页计数查询的mysql问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆