I try to get images on search by criteria. firstly i got result correctly. but click next page the result shown to me wrong result. this is my code.can any help...
<?PHP
if(!isset($_GET))
{
$page = 1;
}
else
{
$page = $_GET;
}
include("connect.php");
$max_results = 8;
$from = (($page * $max_results) - $max_results);
$width = 120;
$height = 130;
$search = $_POST["search"];
$category = $_POST["list"];
echo $category;
{
echo "<table border=0><tr>";
?>
<span class="style1">Please Enter a criteria</span><?PHP echo "</tr></table>";
}
else
{
$str = "select * from images where Description like '%" . mysql_real_escape_string($search) . "%' and Category='$category' LIMIT $from, $max_results ";
$res = mysql_query($str);
$trows = mysql_num_rows($res);
if($trows ==0)
{
echo "<br>";
echo "Your search doesn't match with" . " " . $search;
}
else
{
echo '<table width="400" border="0" class="bodi" cellspacing="12" cellpadding="12" align="center">';
$colsPerRow = 4;
$colWidth = (int)(100/$colsPerRow);
$j = 0;
while($row = mysql_fetch_array($res))
{
if ($j % $colsPerRow == 0) {
echo '<tr>';
}?>
<td valign= top align= center width='<?PHP $colWidth; ?>' <a href="#" onClick="openWin('fileName=<?PHP echo $row; ?>')"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#8A728D"><img border="1" width="<? print $width;?>" height="<? print $height;?>" src='<?PHP echo $row; ?>' ></a><br><?PHP echo $row; ?></font> </td>
<?PHP
if ($j % $colsPerRow == $colsPerRow - 1) {
echo '</tr>';
}
$j += 1;
}
if ($j % $colsPerRow != 0) {
while ($j++ % $colsPerRow != 0) {
echo '<td width="' . $colWidth . '%"> </td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
<?PHP
{
if($i==1)
{
}}
?>
<?php
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as File FROM images where Description like '%" . mysql_real_escape_string($search) . "%' and Category='$category'"),0);
$total_pages = ceil($total_results / $max_results);
echo "<center> <br />"; ?>
<table><tr><td>
<?PHP
if($total_pages!= 0)
{
if($page > 1){
$prev = ($page - 1);
echo "<a href=searchimage.php?page=$prev\ > Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=searchimage.php?page=$i> $i</a>";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=searchimage.php?page=$next\> Next</a>";
}
}
echo "</center>"; ?>