Jump to content

[SOLVED] Pagination error! needs your HELP!!


robert_gsfame

Recommended Posts

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>";

 

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.