etdsbastar Posted August 26, 2011 Share Posted August 26, 2011 Hello there, Please have a look on the below given code: <?php function renderform($wardno, $demandno, $name) { include_once $_SERVER['DOCUMENT_ROOT'].'/header.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/config/config.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/functions/functions.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/functions/connect-db.php'; extract($GLOBALS); ?> <link rel=stylesheet HREF="/css/sp.css" type="text/css" media="screen"> <div id="content"> <div id="labelopt"></div> <h2>okMZokj ukxfjdksa dh lwph</h2> <div id="dp-sp"> <form name="spsearchform" action="" method="post"> <table border="1"> <tr> <td id="labelmust" width="10%">fM- dz- %</td> <td><input class="english" type="text" size="15%" name="demandno" maxlength="40" value="<?php echo $demandno; ?>" /></td> <td id="labelmust" width="10%">okMZ dz- %</td> <td><input class="english" size="20%" type="text" size="15%" name="wardno" maxlength="3" value="<?php echo $wardno; ?>"/></td> <td id="labelmust" width="10%">uke %</td> <td><input class="hindi" size="30%" type="text" name="name" maxlength="100" value="<?php echo $name; ?>"/></td> <td><input type="submit" value="Search" name="btnsearch" /></td> </tr> </table> </form> <table border="1" cellpadding="2px"> <tr> <td id="labelcenter">okMZ dz-</td> <td id="labelcenter">fMeka.M dzekad</td> <td id="labelcenter">uke</td> <td id="labelcenter">irk</td> <td id="labelcenter">Hkqxrku</td> <td id="labelcenter">fu;kstu</td> <td id="labelcenter">feVk;sa</td> </tr> <?php if ($demandno == '' && $wardno == '' && $name == '') // all empty. { $result = mysql_query("SELECT * FROM sform order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name != '') // all full. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name == '') // demand full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name == '') // demand and ward full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name == '') // ward full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name != '') // ward and name full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno == '' && $name != '') // name full else empty. { $result = mysql_query("SELECT * FROM sform where (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name != '') // demand and name full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } $perpage = 20; $totalresults = mysql_num_rows($result); $totalpages = ceil($totalresults / $perpage); if (isset($_GET['page']) && is_numeric($_GET['page'])) { $showpage=$_GET['page']; if ($showpage > 0 && $showpage <= $totalpages) { $start = ($showpage - 1) * $perpage; $end = $start + $perpage; } else { // error - show first set of results $start = 0; $end = $perpage; } } else { // if page isn't set, show first set of results $start = 0; $end = $perpage; } echo "<div id='labelmust'><blink>dqy ukxfjd% $totalresults</blink></div><div id='labelmust'></div>"; echo "<div align='center' style='margin-right: 10px; color: darkgreen;'>"; for ($i = 1; $i <= $totalpages; $i++) { echo "<a href='splist.php?page=$i'>$i</a> "; } echo "</div>"; if ($totalresults > 0) { for($i=$start; $i<=$end; $i++) { if ($i == $totalresults) { break; } echo "<tr>"; echo '<td width="10%"><center>' . mysql_result($result, $i, 'wardno') . '</center></td>'; echo '<td width="10%" id=\'labelenglish\'><center>' . mysql_result($result, $i, 'demandno') . '</center></td>'; echo '<td width="30%">' . mysql_result($result, $i, 'name') . '</td>'; echo '<td width="30%">' . mysql_result($result, $i, 'address') . '</td>'; echo '<td><center><a href="sppayment.php?demandno=' . mysql_result($result, $i, 'demandno') . '">Hkqxrku</center></a></td>'; echo '<td><center><a href="spedit.php?demandno=' . mysql_result($result, $i, 'demandno') . '">cnysa</center></a></td>'; echo '<td><center><a href="spdelete.php?demandno=' . mysql_result($result, $i, 'demandno') . '">feVk;sa</center></a></td>'; echo "</tr>"; } } else { echo "<tr>"; echo "<td colspan='7' align='center'><blink><strong>lwph miyC/k ugha gS A</strong></blink></td>"; echo "</tr>"; } ?> </tr> </table> </div> <?php echo "<div align='center' style='margin-right: 10px; color: darkgreen;'>"; for ($i = 1; $i <= $totalpages; $i++) { echo "<a href='splist.php?page=$i'>$i</a> "; } echo "</div>"; ?> <div id="menu"> <table> <tr> <td> <input type="button" name="btnprint" value="Print" /> <input type="button" value="New" name="btnnew" onclick="location.href='spnew.php';" /> <input type="button" value="Back" name="btnspback" onclick="location.href='../sp.php';" /> </td> </tr> </table> </div> </div> <?php include_once $_SERVER['DOCUMENT_ROOT'].'/footer.php'; } include_once $_SERVER['DOCUMENT_ROOT'].'/functions/connect-db.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/functions/functions.php'; if(isset($_POST['btnsearch'])) { $demandno = mysql_real_escape_string(htmlspecialchars($_POST['demandno'])); $wardno = mysql_real_escape_string(htmlspecialchars($_POST['wardno'])); $name = mysql_real_escape_string(htmlspecialchars($_POST['name'])); renderform($demandno, $wardno, $name); } else { renderform('', '', ''); } ?> In the above code the pagination is working perfectly. After entering any value in the textboxes and pressing the search button also gives me the correct results with pagination. The problem occurs when we press the page links after any search. It shows the complete results again, rather than changing pages in the current search. Please help... Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/ Share on other sites More sharing options...
QuickOldCar Posted August 27, 2011 Share Posted August 27, 2011 Take a look here. http://www.phpfreaks.com/tutorial/basic-pagination Take particular attention of the mysql query using LIMIT $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage"; mysql results offset begins at zero, and how many results from that point (where to start from / amount per page) Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262549 Share on other sites More sharing options...
etdsbastar Posted August 27, 2011 Author Share Posted August 27, 2011 Take a look here. http://www.phpfreaks.com/tutorial/basic-pagination Take particular attention of the mysql query using LIMIT $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage"; mysql results offset begins at zero, and how many results from that point (where to start from / amount per page) I am a newbie dear, I have read the link and understood the logic a little bit. Please tell me the changes to be made in my code, so that I can understand the logic in a more better way. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262578 Share on other sites More sharing options...
etdsbastar Posted August 27, 2011 Author Share Posted August 27, 2011 anybody, please help... Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262589 Share on other sites More sharing options...
sasa Posted August 27, 2011 Share Posted August 27, 2011 save variable for search in sessino and then use it in your function ... session_start(); include_once $_SERVER['DOCUMENT_ROOT'].'/functions/connect-db.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/functions/functions.php'; if(isset($_POST['btnsearch'])) { // if form was submited add variable to session $_SESSION['demandno'] = mysql_real_escape_string(htmlspecialchars($_POST['demandno'])); $_SESSION['wardno'] = mysql_real_escape_string(htmlspecialchars($_POST['wardno'])); $_SESSION['name'] = mysql_real_escape_string(htmlspecialchars($_POST['name'])); } //call function with session variables renderform($_SESSION['wardno'], $_SESSION['demandno'], $_SESSION['name']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262603 Share on other sites More sharing options...
etdsbastar Posted August 27, 2011 Author Share Posted August 27, 2011 I tried with following errors and warnings, no results: Warning: session_start(): Cannot send session cookie Warning: session_start(): Cannot send session cache limiter and the results are also coming awkward... means nothing... Please help. Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262641 Share on other sites More sharing options...
etdsbastar Posted August 27, 2011 Author Share Posted August 27, 2011 please help... Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262675 Share on other sites More sharing options...
etdsbastar Posted August 27, 2011 Author Share Posted August 27, 2011 anybody please help... its very urgent. Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262697 Share on other sites More sharing options...
etdsbastar Posted August 28, 2011 Author Share Posted August 28, 2011 pls help bump Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262824 Share on other sites More sharing options...
etdsbastar Posted August 28, 2011 Author Share Posted August 28, 2011 Hello again, the below give code is not working with search results... please help. Here is the slight modified code: <?php function renderform($wardno, $demandno, $name) { include_once $_SERVER['DOCUMENT_ROOT'].'/npms/header.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/config/config.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php'; extract($GLOBALS); ?> <link rel=stylesheet HREF="/npms/css/sp.css" type="text/css" media="screen"> <div id="content"> <div id="labelopt"></div> <h2>okMZokj ukxfjdksa dh lwph</h2> <div id="list"> <form name="spsearchform" action="" method="post"> <table border="1" cellpadding="2px"> <tr> <td id="labelmust" width="10%">fM- dz- %</td> <td><input class="english" type="text" size="15%" name="demandno" maxlength="40" value="<?php echo $demandno; ?>" /></td> <td id="labelmust" width="10%">okMZ dz- %</td> <td><input class="english" size="20%" type="text" size="15%" name="wardno" maxlength="3" value="<?php echo $wardno; ?>"/></td> <td id="labelmust" width="10%">uke %</td> <td><input class="hindi" size="30%" type="text" name="name" maxlength="100" value="<?php echo $name; ?>"/></td> <td><input type="submit" value="Search" name="btnsearch" /></td> </tr> </table> </form> <table border="1" cellpadding="2px"> <tr> <td id="labelcenter">okMZ dz-</td> <td id="labelcenter">fMeka.M dzekad</td> <td id="labelcenter">uke</td> <td id="labelcenter">irk</td> <td id="labelcenter">dj fooj.k</td> <td id="labelcenter">fu;kstu</td> <td id="labelcenter">feVk;sa</td> </tr> <?php if ($demandno == '' && $wardno == '' && $name == '') // all empty. { $result = mysql_query("SELECT * FROM sform order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name != '') // all full. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name == '') // demand full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name == '') // demand and ward full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name == '') // ward full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name != '') // ward and name full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno == '' && $name != '') // name full else empty. { $result = mysql_query("SELECT * FROM sform where (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name != '') // demand and name full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and (name like '%$name%') order by wardno, id, demandno") or die(mysql_error()); } $perpage = 50; $totalresults = mysql_num_rows($result); $totalpages = ceil($totalresults / $perpage); if (isset($_GET['page']) && is_numeric($_GET['page'])) { $showpage=$_GET['page']; if ($showpage > 0 && $showpage <= $totalpages) { $start = ($showpage - 1) * $perpage; $end = $start + $perpage; } else { // error - show first set of results $start = 0; $end = $perpage; } } else { // if page isn't set, show first set of results $start = 0; $end = $perpage; } if ($totalresults > 0) { echo "<div id='pages'>"; for ($i = 1; $i <= $totalpages; $i++) { echo "<small>| <a href='splist.php?page=$i'>$i</a> </small>"; } echo "<small> |</small>"; echo "</div>"; } if ($totalresults > 0) { for($i=$start; $i<=$end; $i++) { if ($i == $totalresults) { break; } echo "<tr>"; echo '<td id="english"><center>' . mysql_result($result, $i, 'wardno') . '</center></td>'; echo '<td id="english"><center>' . mysql_result($result, $i, 'demandno') . '</center></td>'; echo '<td id="hindi">' . mysql_result($result, $i, 'name') . '</td>'; echo '<td id="hindi">' . mysql_result($result, $i, 'address') . '</td>'; echo '<td><center><a href="payments/taxreport.php?demandno='.mysql_result($result, $i, 'demandno').'"><img src="../images/payment.jpeg" width="15" height="15" /></a></center></td>'; echo '<td><center><a href="spedit.php?demandno='.mysql_result($result, $i, 'demandno').'"><img src="../images/edit.gif" width="15" height="15" /></center></a></td>'; echo '<td><center><a href="spdelete.php?demandno='.mysql_result($result, $i, 'demandno').'"><img src="../images/delete.jpeg" width="15" height="15" /></center></a></td>'; echo "</tr>"; } } else { echo "<tr>"; echo "<td colspan='7' align='center'><blink><strong>lwph miyC/k ugha gS A</strong></blink></td>"; echo "</tr>"; } ?> </tr> </table> </div> <?php if ($totalresults > 0) { echo "<div id='pages'>"; for ($i = 1; $i <= $totalpages; $i++) { echo "<small>| <a href='splist.php?page=$i'>$i</a> </small>"; } echo "<small> |</small>"; echo "</div>"; } ?> <div id="menu"> <table> <tr> <td> <input type="button" value="New" name="btnnew" onclick="location.href='spnew.php';" /> <input type="button" value="Back" name="btnspback" onclick="location.href='../sp.php';" /> </td> </tr> </table> </div> </div> <?php include_once $_SERVER['DOCUMENT_ROOT'].'/npms/footer.php'; } include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php'; if(isset($_POST['btnsearch'])) { $wardno = mysql_real_escape_string(htmlspecialchars($_POST['wardno'])); $name = mysql_real_escape_string(htmlspecialchars($_POST['name'])); $demandno = mysql_real_escape_string(htmlspecialchars($_POST['demandno'])); renderform($demandno, $wardno, $name); } else { renderform('', '', ''); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245793-please-help-pagination-problem/#findComment-1262900 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.