954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error in pagination of search engine

Hi everyone, I am trying to implement pagination in my search engine and am getting an error. Can anyone point out what is wrong in my code? Any help would be greatly appreciated. Thanks.


Here is the code, error is:

( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\search2\search.php on line 44

<html>
<head>


</head>
<body>
<center>
<form method="GET" action="search.php">

      <input type="text" name="search">
      <input type="submit" name="submit" value="search database">
      
</form>
</center>
<hr />

<?php

if(isset($_REQUEST['submit'])) {

       $search = $_GET['search'];
       $terms = explode(" ", $search);
       $query = "SELECT * FROM oldsaybrook WHERE ";


       $i=0;
       foreach($terms as $each) {
        $i++;
        if($i==1){
             $query .= "name LIKE '%$each%' OR address LIKE '%$each%' LIMIT $start, $per_page ";

        }else{
          $query .= "OR name LIKE '%$each$' OR address LIKE '%$each%' LIMIT $start, $per_page ";
        }
       }

       mysql_connect("localhost", "root", "");
       mysql_select_db("wfl_rest");

       $per_page = 10;
       $query = mysql_query($query);
       $num = mysql_num_rows($query);
       $pages = ceil(mysql_result($num, 0 / $per_page);
       $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
       $start = ($page - 1) * $per_page;



       if($num > 0 && $search!=""){

           echo "$num result(s) found for $search! ";

           while($row = mysql_fetch_assoc($query)){

                $id = $row['id'];
                $name = $row['name'];
                $address = $row['address'];
                $url = $row['url'];

                echo "$name$url$address";

           }


       }  else {

               echo "No results found";

       }





} else {

  echo "Please type any word...";
  
}

     $prev = $page - 1;
     $next = $page + 1;


     if(!($page<=1)){
     echo "<a href='search.php?page=$prev'>Prev</a> ";
     }


     if($pages >= 1){

       for($x=1;$x<=$pages;$x++){

         echo ($x == $page) ? '<b><a href="?page='.$x.'">'.$x.'</a></b> ':'<a href="?page='.$x.'">'.$x.'</a> ';

       }
     }

          if(!($page>=$pages)){
          echo "<a href='search.php?page=$next'>Next</a> ";
      }



?>

</body>
</html>
whoatommy
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 
$pages = ceil(mysql_result($num, 0 / $per_page);


That looks freaky.

0 / $per_page


will give you a value below 1, so which record were you trying to retrieve? is this what you want?

$pages = ceil(mysql_result($num, 0)/ $per_page);


But $num should be the result resource - check out the php.net manual on mysql_result.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

$pages = ceil(mysql_result($num, 0 / $per_page));

You are missing a close parenthesis, causing the syntax error.

cscgal
The Queen of DaniWeb
Administrator
19,437 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 
You are missing a close parenthesis, causing the syntax error.


Indeed!

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: