tapantor24 Posted December 4, 2013 Share Posted December 4, 2013 Look at this code. This is search function with pagination. I want to use this code in project of my client but problem is that the search result show on first page normally but when i press next button it's going wrong. It's show no category found. I spend many tiime to solve this but result is zero. Pls help me any one to solve thise.. <?php //include out functions file giving us access to the protect() function made earlier include "./include/database.php"; ?> <?php $phone = ($_POST['phone']); $productsPerRow = 2; $perpage = 10; if(isset($_GET["page"])) { $page = intval($_GET["page"]); } else { $page = 1; } $calc = $perpage * $page; $start = $calc - $perpage; $result = mysql_query("SELECT * FROM `bookmark` WHERE `phone` = '$phone' Limit $start, $perpage"); $rows = mysql_num_rows($result); $columnWidth = (int)(100 / $productsPerRow); if($rows>0){ $i=0; ?> <table width='100%' border='0' align='center' cellpadding='5' cellspacing='1' class='bookmark'> <?php while($row = mysql_fetch_array($result)) { //$row['Photo'] = "<img src="/user_image/ . $row['Photo']; ""/> if ($i % $productsPerRow == 0) { ?> <tr > <?php } $Sub =$row['Sub']; $url=$row['Link']; $Phone =$row['phone']; $info =$row['info']; ?> <td width="$columnWidth%" >Subject: <?php echo $row['Sub'];?><br/> Link: <?php echo $row['Link'];?><br/> Mobile: <?php echo $row['phone'];?><br/> Information: <?php if($info != '') { ?> <?php echo $row['info'];?> <?php }else { echo "N/A"; } ?> </td> <?php if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> No products in this category <?php } ?> </table> <table width="100%" cellspacing="2" cellpadding="2" align="center" > <tr> <td align="center"> <?php if(isset($page)) { $result = mysql_query("select Count(*) As Total from bookmark WHERE `phone` = '$phone'"); $rows = mysql_num_rows($result); if($rows) { $rs = mysql_fetch_array($result); $total = $rs["Total"]; } $totalPages = ceil($total / $perpage); if($page <=1 ) { echo "<span id='page_links' style='font-weight:bold;'>Prev</span>"; } else { $j = $page - 1; echo "<span><a id='page_a_link' href='info5.php?page=$j'>< Prev</a></span>"; } for($i=1; $i <= $totalPages; $i++) { if($i<>$page) { echo "<span><a href='info5.php?page=$i' id='page_a_link'>$i</a></span>"; } else { echo "<span id='page_links' style='font-weight:bold;'>$i</span>"; } } if($page == $totalPages ) { echo "<span id='page_links' style='font-weight:bold;'>Next ></span>"; } else { $j = $page + 1; echo "<span><a href='info5.php?page=$j' id='page_a_link'>Next</a></span>"; } } ?> <td> </tr> </table> <form action="info5.php" method="POST"> <input name="phone" id="phone" type="text" size="25" class="box" value="Type Mobile No…" onfocus="this.value=(this.value=='Type Mobile No…')? '' : this.value ;" /> <input type="submit" name="submit" class="box" id="submit" value="Search" /> </form> Quote Link to comment Share on other sites More sharing options...
dalecosp Posted December 4, 2013 Share Posted December 4, 2013 (edited) If you're sure that products *should* be found on a second page, have the script echo the values of $start and $perpage to you just before the query ... it may be that these values are not what you expect.Also, please consider using the [ code ] BB tags for your code Edited December 4, 2013 by dalecosp Quote Link to comment Share on other sites More sharing options...
tapantor24 Posted December 5, 2013 Author Share Posted December 5, 2013 (edited) It's a long database. It's will show 10 result each page. First page going fine but next show no category found. It's also going fine when i replace this WHERE `phone` = '$phone' to WHERE ’phone’ = ’01736659047 ’ or manually type any number from the database. Edited December 5, 2013 by tapantor24 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 5, 2013 Share Posted December 5, 2013 web servers are stateless. they don't have any idea what happened on any page request before or after the current one. you $phone value will only exist on the page request that the search form was submitted to. you need to pass the $phone value in the pagination links so that it is available on those page requests. Quote Link to comment Share on other sites More sharing options...
tapantor24 Posted December 5, 2013 Author Share Posted December 5, 2013 Pls show the code how it will be. Thx Quote Link to comment Share on other sites More sharing options...
White_Lily Posted December 5, 2013 Share Posted December 5, 2013 is the search terms stored in a session or is the whole ting powered by javascript? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 5, 2013 Share Posted December 5, 2013 i recommend using http_build_query() to build the url query string from various different sources (i.e. a search value and pagination values) - ref: http://it1.php.net/http_build_query Quote Link to comment Share on other sites More sharing options...
Solution dalecosp Posted December 5, 2013 Solution Share Posted December 5, 2013 (edited) Pls show the code how it will be. Thx Come on now friend ... it's not THAT hard //lines like these will need changed: echo "<span><a id='page_a_link' href='info5.php?page=$j'>< Prev</a></span>"; //needs phone parameter echo "<span><a href='info5.php?page=$i' id='page_a_link'>$i</a></span>"; //needs phone parameter //to this echo "<span><a id='page_a_link' href='info5.php?page=$j&phone=$phone'>< Prev</a></span>"; //has phone parameter echo "<span><a href='info5.php?page=$i&phone=$phone' id='page_a_link'>$i</a></span>"; //has phone parameter //At the top, because you're only POSTing the first time (and using GET thereafter), you will need something like: if (isset($_POST['phone'])) { $phone = $_POST['phone']; } elseif (isset($_GET['phone']) { $phone = $_GET['phone']; } And you probably should consider some type of validation on the phone variable as well, unless you're certain that it won't be viewed by anyone except people in your own company. Edited December 5, 2013 by dalecosp Quote Link to comment Share on other sites More sharing options...
tapantor24 Posted December 6, 2013 Author Share Posted December 6, 2013 Many many thx friend @dalecosp It's solve my problem. But how I apply it in many condition. Such as age between age. Thanks again. 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.