Jump to content

Count Query


neha_jaltare

Recommended Posts

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..

Link to comment
Share on other sites

From what you have posted, the variable $WHERE is never defined. There is a tutorial on PHP Freaks itself about pagination http://www.phpfreaks.com/tutorial/basic-pagination I've used this before and it works a charm.

 

A small change I would do is add "or die(mysql_error());" on the end of your queries. Like below...

$result = mysql_query($query) or die(mysql_error());

This would mean if an error occurred with the query, it'll show you what the error is.

 

I'll also say now... "but it is not working properly" does not tell us what the problem is. You must specify what happens and what outputs (if any) and what you want it to do, this will give us a leg to stand on whilst helping you fix your issues.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.