RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 693 | Replies: 0
Reply
Join Date: Jul 2007
Posts: 1
Reputation: nobwe7 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nobwe7 nobwe7 is offline Offline
Newbie Poster

Solution pagination with search by criteria + php

  #1  
Jul 26th, 2007
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']))
{
$page = 1;
}
else
{
$page = $_GET['page'];
}
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['File']; ?>')"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#8A728D"><img border="1" width="<? print $width;?>" height="<? print $height;?>" src='<?PHP echo $row['File']; ?>' ></a><br><?PHP echo $row['Description']; ?></font> </td>


<?PHP

if ($j % $colsPerRow == $colsPerRow - 1) {

echo '</tr>';
}

$j += 1;
}


if ($j % $colsPerRow != 0) {
while ($j++ % $colsPerRow != 0) {
echo '<td width="' . $colWidth . '%">&nbsp;&nbsp;&nbsp;&nbsp;</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\ >&nbsp;Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {


echo "<a href=searchimage.php?page=$i>&nbsp;$i</a>";
}
}

if($page < $total_pages){
$next = ($page + 1);
echo "<a href=searchimage.php?page=$next\>&nbsp;Next</a>";
}
}
echo "</center>"; ?>
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:15 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC