robert_gsfame Posted May 29, 2009 Share Posted May 29, 2009 I want to make a search engine for user and display records in several pages. when i try it, at first page records displayed correctly but when i click on the second page "2" , ">" or ">>", all gone wrong. does anyone can help me? thx in advance!! here is my code: $variable = $_GET['city'] ; $variable2 =$_GET['title'] ; $variable3 =$_GET['field'] ; $variable4 =$_GET['country'] ; $trimmed = trim($variable); $trimmed2 = trim($variable2); $trimmed3 = trim($variable3); $trimmed4 = trim($variable4); $table = "members"; $search = "city"; $search2 = "title"; $search3 = "field"; $search4 = "country"; $query = "SELECT COUNT(*)FROM $table WHERE $search2 LIKE '%$trimmed2%'AND $field_to_search3 LIKE '%$trimmed3%' AND $field_to_search LIKE '%$trimmed%' AND $field_to_search4 LIKE '%$trimmed4%' ORDER BY firstname"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrow = $r[0]; $rowsperpage = 1; $totalpages = ceil($numrow / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $query = "SELECT * FROM $table WHERE $field_to_search2 LIKE '%$trimmed2%'AND $field_to_search3 LIKE '%$trimmed3%' AND $field_to_search LIKE '%$trimmed%' AND $field_to_search4 LIKE '%$trimmed4%' ORDER BY firstname LIMIT $offset, $rowsperpage"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $count = mysql_num_rows($result); $info = mysql_fetch_array($result); $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0 ) { echo "<center><font face=arial><h4>Results</h4></font></center>"; echo "<center><font face=arial size=2><p>Sorry, your search </font>"."<font face=arial size=2> returned zero results</font></p></center>"; } if (empty($s)) { $s=0; } $result = mysql_query($query) or die("Couldn't execute query"); if($numrows > 1 ){$return = "results";} else{ $return = "result"; } echo "<p><font face=arial size=2>Your search </font><font face=arial size=2>returned <strong>$totalpages</strong> $return</font></p>"; $count = $s + 1 ; while ($row= mysql_fetch_array($result)) { $city = $row["city"]; $country = $r["country"]; $count++ ; echo $city.$country } $range = 20; echo"<center>"; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><img src='firstarrow.jpg' width=15 height=15 border=0></a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><img src='previousarrow.jpg' width=15 height=15 border=0></a>"; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo "<font face=arial size=2> [<b>$x</b>] </font>"; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x' class=set6><font face=arial size=2>$x</font></a> "; } } } if ($currentpage < $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'><img src='nextarrow.jpg' width=15 height=15 border=0></a>"; echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'><img src='lastarrow.jpg' width=15 height=15 border=0></a>"; } echo"</center>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/160117-solved-pagination-error-needs-your-help/ Share on other sites More sharing options...
robert_gsfame Posted May 29, 2009 Author Share Posted May 29, 2009 SOLVE !!! i just add "title=$title&field=$field&q=&country=$country&search=Find+resume¤tpage=$x'> in my link and it solves my problem.. FINALLY Quote Link to comment https://forums.phpfreaks.com/topic/160117-solved-pagination-error-needs-your-help/#findComment-845056 Share on other sites More sharing options...
Maq Posted May 29, 2009 Share Posted May 29, 2009 For future reference surround your code with tags. There is also a "topic solved" tab in the bottom left. Quote Link to comment https://forums.phpfreaks.com/topic/160117-solved-pagination-error-needs-your-help/#findComment-845069 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.