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! <br />";
while($row = mysql_fetch_assoc($query)){
$id = $row['id'];
$name = $row['name'];
$address = $row['address'];
$url = $row['url'];
echo "<br />$name<br />$url<br />$address<br />";
}
} 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>