neha_jaltare Posted October 3, 2012 Share Posted October 3, 2012 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.. Quote Link to comment Share on other sites More sharing options...
JLT Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 3, 2012 Share Posted October 3, 2012 If you define what "does not work correctly" means, I'm sure someone can help. Right now we have no idea on what you want nor what you get. I recommend that you read this article. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 3, 2012 Share Posted October 3, 2012 Since there's no evidence OP is using any third party software, and this is a MySQL question, I'm moving it to the right forum. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.