platform wamp5 1.6.6
I wrote a code for searching the database according to the value passed through $_POST.I used pagination to display the pages.
My problem is that when i search, the first page appears with details and links(eg page 1 of 8 next last),but in the next page no details.
after checking i found that $_POST has value in the first time ,thereafter it has no value so the search criteria become false.
what should i do to display all pages correctly.
code
{
$area=$_POST['area'];
$type=$_POST['type'];
$purpose=$_POST['purpose'];
if($purpose=="Any" and $type=="Any"
{
$query1="SELECT * from property where location='$area' ";
$query = "SELECT count(*) FROM property where location='$area' ";
echo 'one'.$query1;
}
elseif($purpose=="Any"
{
$query1="SELECT * from property where location='$area' and ptype='$type' ";
$query = "SELECT count(*) FROM property where location='$area' and ptype='$type'";
}
elseif($type=="Any"
{
$query1="SELECT * from property where location='$area' and mode='$purpose' ";
$query="SELECT count(*) from property where location='$area' and mode='$purpose' ";
}
else
{
$query1="SELECT * from property where location='$area' and mode='$purpose' and ptype='$type'";
$query="SELECT count(*) from property where location='$area' and mode='$purpose' and ptype='$type'";
}
retrieve_search_page($query,$query1);
}
function retrieve_search_page()
<?php
function retrieve_search_page($query,$query1)
{
$conn = db_connect();
if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
}
else {
$pageno = 1;
}
$result = mysqli_query( $conn,$query);
if(!$result)
{
echo 'error.';
do_html_footer();
exit;
}
else
{
$query_data = mysqli_fetch_row($result);
$numrows = $query_data[0];
}
$rows_per_page = 5;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1)
{
$pageno = 1;
}
elseif ($pageno > $lastpage)
{
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
// Issue the database query
$query1=$query1.$limit;
$result = mysqli_query($conn,$query1);
if(!$result)
{
echo 'No result fund ,that match your search criteria.';
do_html_footer();
exit;
}
else
{
$num_row=mysqli_num_rows($result);
}
for($i=0;$i < $num_row;$i++)
{
$row=mysqli_fetch_assoc($result);
$id1 = $row['id'];
$id='gk'.$id1;
$location= $row['location'];
$barea= $row['barea'];
$mode= $row['mode'];
$email=$row['email'];
$price= $row['price'];
$type= $row['ptype'];
$description= $row['description'];
$date= $row['date'];
$description=stripslashes($description);
$description=substr($description,0,100);
?>
// display result
<?php
}
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage)
{
echo " NEXT LAST ";
}
else
{
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
}
?>
if i use a query other than $_POST(eg; $query="select * from property where location='India'"
i can display all pages.what should i do to maintain the value.i used session ,but after the first page its value also reset or null.
pls help me
Post Edited (12-12-06 11:27)