I want my code to execute a query based on the values in the search keyword text boxes. But the current code executes the default query each time at the time of loading, Help. Any help will be appreciated. Plz help
rentals_search.template.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css"> </link>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RBlog - For the Consumers - By the Sellers</title>
<?
require_once("common/class.Database.php");
?>
</head>
<body>
<?php include("includes/header.php"); ?>
<?php include("dbclass/paging_class.php"); ?>
<div class="afterpicer_total">
<?php include("includes/menu.php"); ?>
<div class="wrapper">
<div class="cont">
<?php include("includes/left_menu.php"); ?>
<div class="reg_cont">
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="reg_label">Looking for</div>
<div class="reg_tbox">
<select name="type" class="reg_combo_style">
<option>Living House</option>
<option>Office</option>
</select>
</div><br/>
<div class="reg_label">Rent/Month</div>
<div class="reg_tbox">
<select name="rent" class="reg_combo_style">
<option></option>
<option><2000</option>
<option>2000-4000</option>
<option>4000-6000</option>
<option>6000-10000</option>
<option>>10000</option>
</select>
</div><br/>
<div class="reg_label" >City</div>
<div class="reg_tbox">
<select name="city" class="reg_combo_style">
<option></option>
<option>Chennai</option>
<option>Salem</option>
<option>Madurai</option>
<option>Trichy</option>
</select>
</div><br/>
<div class="reg_label" >Area</div>
<div class="reg_tbox"><input type="text" size="32" name="area" class="reg_tbox_style" ></input></div><br/><br/>
<?php
//doPages(10, '/rentals_search.php', 'city=Madurai', 5);
$newpage=new paging();
$newpage->pager();
?>
<div class="reg_tbox"><input type="submit" name="subm" value="Search" class="reg_but_style"style="margin-left:155px;"></input></div>
<div class="reg_bl"></div>
</form>
</div>
</div>
<div class="adspace"> Advertisement Space</div>
</div>
</div>
</body>
</html>
paging_class.php
<?php
ob_start();
require_once("common/class.Database.php");
require_once("common/varDeclare.php");
class paging extends Database
{
function pager()
{
$rowsPerPage = 3;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM rentals_ads" ." LIMIT $offset, $rowsPerPage";
//$query="SELECT * FROM ads WHERE rentals_type = 'Living House' AND rent > 50 AND rent < 300 AND city = 'London' AND area LIKE '%westminster%'"." LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query1 failed');
// print the random numbers
while($row = mysql_fetch_array($result))
{
echo $row['rentals_title'] . '';
echo $row['rentals_type'].' ';
echo $row['city'].'<br>';
}
// ... more code here
// ... the previous code
// how many rows we have in database
$query = "SELECT COUNT(rentals_title) AS numrows FROM rentals_ads";
$result = mysql_query($query) or die('Error, query2 failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// ... still more code coming
// ... the previous code
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
// ... and we're done!
}
}
?>
// ---- End of addDB()------