Jump to content

neha_jaltare

New Members
  • Posts

    7
  • Joined

  • Last visited

Profile Information

  • Gender
    Female

neha_jaltare's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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..
  2. But why we use sprintf function here? Sorry sir , Actually I am beginner that's why I am asking many quetions to you.
  3. // get and condition any search term $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $where_clause = ''; if($search != ''){ // form a simple LIKE '%search term%' comparison $where_clause = sprintf("WHERE your_column LIKE '%%%s%%'",mysql_real_escape_string($search)); } I don't understand these line.Why do you use it. Is it necessary?
  4. PFMaBiSmAd, Can you please explain me little bit of above coding.I don't want to use here copy and paste method. Thanks for the reply to my question..
  5. Hello, I am facing one problem of pagination. Actually I did pagination successfully,but problem is getting by where clause I used SELECT query with WHERE clause.Using input field. Now the problem is that "while choosing the page of that pagination I have to again choose that input fields which used in the where clause. Here is my piece of code : Collapse | Copy Code <?php $i = 0; if(!empty($_POST['select2'])) { foreach ($_POST['select2'] as $selectedOption) { $options[$i++] = $selectedOption; } } if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } $sql ="select DISTINCT date,mobno,city,state,type,telecaller,time FROM import"; $query = mysql_query($sql); $query_data = mysql_num_rows($query); $numrows = $query_data; $rows_per_page = 10; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } if ($pageno < 1) { $pageno = 1; } $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN("; $num = count($options); for ($i=0; $i<$num-1; $i++) { $sql .= "'".$options[$i]."', "; } $sql .= "'".$options[$i]."')"; $sql .= "GROUP BY mobno,telecaller ORDER BY date DESC $limit"; // OR date1='$_POST[date]' //echo $sql . "<br>"; $query = mysql_query($sql); echo"<div id='pagination'>"; if ($pageno == 1) { echo " FIRST PREV &nbsp &nbsp &nbsp "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> &nbsp &nbsp &nbsp "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> &nbsp &nbsp &nbsp "; } echo"</div>"; echo"<div id='pagination1'>"; echo " ( Page <b>$pageno</b> of $lastpage ) &nbsp &nbsp &nbsp"; echo"</div>"; echo"<div id='pagination2'>"; if ($pageno == $lastpage) { echo " NEXT LAST &nbsp &nbsp &nbsp"; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> &nbsp &nbsp &nbsp"; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } echo"</div>";
  6. Here is my whole code <?php $i = 0; if(!empty($_POST['select2'])) { foreach ($_POST['select2'] as $selectedOption) { $options[$i++] = $selectedOption; } } $num = count($options); for ($i=0; $i<$num-1; $i++) { $option1 = "'".$options[$i]."',"; } $option1 .= "'".$options[$i]."'"; $option2=$_SESSION[$option1]; echo $option2; $per_page=6; $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN($option1)GROUP BY mobno,telecaller ORDER BY date DESC"; $pages_query= mysql_query($sql); $pages=ceil(mysql_result($pages_query, 0)/$per_page); //$pages=floor(mysql_result($pages_query, 0)/$per_page); $page=(isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start=($page-1) * $per_page; $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN($option1) GROUP BY mobno,telecaller ORDER BY date DESC LIMIT $start,$per_page"; $query= mysql_query($sql); /* Pagination Complete */ print"<div id='print'>"; print"<center>List of Mobile Numbers for Date <font color='#FF00FF'><U> $_POST[date]</U> </font> <center> <br/>"; print"<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>"; $srno1=0; while($row=mysql_fetch_array($query )) { $srno1=$srno1+1; print"<tr>"; print"<td>" .$srno1. "</td>"; print"<td>" . $row['date'] . "</td>"; print"<td>" . $row['mobno'] . "</td>"; print"<td>" . $row['city'] . "</td>"; print"<td>" . $row['state'] . "</td>"; print"<td>" . $row['type'] . "</td>"; print"<td>" . $row['telecaller'] . "</td>"; print"</tr>"; } print"</table>"; print"</div>"; echo"<br/>"; print"<input type='button' value='Print' onclick='fnPrintArea()' /> <br />"; print"<form name='form' method='GET' action='export.php'>"; print"<input type='hidden' name='text1' value='$_POST[date]' id='text1_1'/><br/>"; print"<input type='submit' name='submit2' value='Export This Record' />"; print"</form>"; if($pages>=1 && $page<=$pages){ for($x=1;$x<=$pages;$x++){ echo ($x==$page) ? '<strong><a style="text-decoration:none" href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> '; } } ?> </div> <div id="menu1"> <ul> <li><a href="telecaller.php" title="search all record for perticular telecaller using that date">Search by CIExe.</a></li> <li><a class="current" href="systemdate.php" title="Search record with date and time for all CIExe.s">Search by Date </a></li> <li><a href="mobileno.php" title="Search record individually for either perticular mobile no or CIExe.">Search Mobile No./CIExe.</a></li> </ul> </div> <a href="export3.php" class="button blue alt-gradient" id="href">Export All Record</a> </body> Please tell me you have any doubt about this code.
  7. Actually I have same problem with that pagination . I have to search using multiple combo box values.When I clicked on next button didn't get anything :'( . I tried Psycho's solution but still :'( Here is my code <?php $i = 0; if(!empty($_POST['select2'])) { foreach ($_POST['select2'] as $selectedOption) { $options[$i++] = $selectedOption; } } $num = count($options); for ($i=0; $i<$num-1; $i++) { $option1 = "'".$options[$i]."',"; } $option1 .= "'".$options[$i]."'"; //echo $option1; if(isset($option1)) { $model= mysql_real_escape_string(trim($option1)); $_SESSION[$option1]=$model; } elseif(isset ($_SESSION[$option1])) { $model= $_SESSION[$option1]; } else { echo "There is an error in your query". mysql_error; } /* Pagination Start */ $per_page=6; $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN($option1)GROUP BY mobno,telecaller ORDER BY date DESC"; $pages_query= mysql_query($sql); $pages=ceil(mysql_result($pages_query, 0)/$per_page); //$pages=floor(mysql_result($pages_query, 0)/$per_page); $page=(isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start=($page-1) * $per_page; $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN($option1) GROUP BY mobno,telecaller ORDER BY date DESC LIMIT $start,$per_page"; $query= mysql_query($sql); if($pages>=1 && $page<=$pages){ for($x=1;$x<=$pages;$x++){ echo ($x==$page) ? '<strong><a style="text-decoration:none" href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> '; } . Is there any alternative solution for this code? Thanks in advance.
×
×
  • 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.