In this db and query are working and the firs page but after the 2nd page the variables are not passing can any one help me on this
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("../init/db.php");
$yearfom = $_POST["yearFrom"];
$yearTo = $_POST["yearTo"];
$Year ="SELECT";
if($yearfom!="SELECT"){
$Year ="";
}
$content = array("make"=>$_POST["make"],
"model"=>$_POST["model"],
"year"=>"$Year");
$validValues=array();
foreach ($content as $key=>$value)
{
if($value != "SELECT")
{
$validValues[$key]=$value;
}
}
$query ="select * from cars where ";
foreach($validValues as $key=>$value)
{
$query1 = $query.$key."='".$value."' AND ";
$qu1=true;
if($key == "year"){
$query1 = substr($query1,0,-8);
$query2 = $query1." BETWEEN '".$yearfom."' AND ' ".$yearTo."' ";
$qu1=false;
$qu2=true;
}
}
if($qu1==true){
$query = substr($query1,0,-4);
echo $sql = $query;
}elseif($qu2==true){
$query = $query2;
echo $sql = $query;
}
// how many rows to show per page
$rowsPerPage = 2;
// 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;
// $sql= "select * from cars where year BETWEEN '2007' AND ' 2009' ";
$result=mysql_query($sql);
$row=mysql_num_rows($result);
while($info=mysql_fetch_array($result)){
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$features = $info['features'];
$year= $info['year'];
$pic1=$info['pic1'];
$pic2=$info['pic2'];
$pic3=$info['pic3'];
$id = $info['id'];
$desc=str_replace ("<li>", " ", $features);
$ftt = substr($desc,0,120).".................";
$abc="'viewad.php?id=$id'";
echo '<div id="adcontent"><a onclick="javascript:popUp('.$abc.')"">
<div id="cars">
<div style="background-color:#0091DE; padding:5px; font-weight: bold; color:#FFF;">
'.$make.' - '.$model.' - '.$year.'
</div>
<div style="padding:10px; font-size: 30px;">
<img src="'.$pic1.'" width="20%" height="20%" style="margin:5px;"/>
<img src="'.$pic2.'" width="20%" height="20%" style="margin:5px;" />
<img src="'.$pic3.'" width="20%" height="20%"style="margin:5px;"/> $ '.$price.'
</div>
<div style="padding: 15px;">
<P style="font-size: 12px; font-weight: normal;">
'. $ftt.'
</P>
</div>
<img src="image/images/carbot.gif" width="500" height="10" />
</div></a>
</div>';
}
// how many rows we have in database
$foreditqu= substr($sql,19,-1);
echo $foreditqu;
$query = "SELECT COUNT(id) AS numrows FROM cars ".$foreditqu;
echo $query;
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo "<br />".$numrows = $row['numrows'];
echo "<br />";
// how many pages we have when using paging?
echo $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> ";
}
}
// 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;
?>
<form id="form1" name="F2" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<div style="background-color:#84C8FD; text-align: center;">
<h2>Find a Car</h2>
</div>
<table width="224" border="0">
<tr>
<td width="42">Make</td>
<td colspan="2"><label for="make"></label>
<select name="make" id="master">
<option value="SILECT">Select</option>
<option value="AC">AC </option>
<option value="ALFA ROMEO ">ALFA ROMEO </option>
<option value="ASIA ">ASIA </option>
<option value="AMAROO ">AMAROO </option>
<option value="ASTON MARTIN ">ASTON MARTIN </option>
<option value="AUDI ">AUDI </option>
<option value="AUSTIN ">AUSTIN </option>
<option value="AUSTIN HEALEY ">AUSTIN HEALEY </option>
<option value="BEDFORD ">BEDFORD </option>
<option value="BENTLEY ">BENTLEY </option>
<option value="BERTONE ">BERTONE </option>
<option value="BMW ">BMW </option>
</select></td>
</tr>
<tr>
<td>Model</td>
<td colspan="2"><label for="model"></label>
<select name="model" id="slave">
<option value="SELECT">Select</option>
</select></td>
</tr>
<tr>
<td>Year</td>
<td width="80"><label for="yearFrom"></label>
<select name="yearFrom" id="yearFrom">
<option value="SELECT">From</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select></td>
<td width="80"><select name="yearTo" id="yearTo">
<option value="SELECT">To</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="input" type="submit" value="Search" />
</td>
</tr>
</table>
</form>
</body>
</html>