i have done a search script and now when i try something to search it give me the frist five rows(beacuse the limit is set to 5 rows per page) related to the search.When i click on the "next page" link it gives me the rows from the hole table instead to continue the rows from the search.
here is the code
<?php
$connection=mysql_connect('localhost', 'root', '***') or die(mysql_error());
mysql_select_db("database");
$posts_per_page = 5;
(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
$query = "SELECT COUNT(*) FROM posts WHERE Description like '%".$_GET['Search']."%' or Topic like '%".$_GET['Search']."%'";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_row($result);
$total_records = $row[0];
if (mysql_num_rows($result) > 0 )
{
if (($total_records > 0) && ($start < $total_records))
{
$query="SELECT * FROM Posts WHERE Description like '%".$_GET['Search']."%' or Topic like '%".$_GET['Search']."%' ORDER BY ID desc LIMIT $start, $posts_per_page";
$result = mysql_query($query) or die (mysql_error());
}
include "PrintRows.php";
//next previous page links
if ($start >= $posts_per_page)
{
echo "<a href=".$_SERVER['PHP_SELF']."?start=".($start-$posts_per_page)."> <= $start </a>";
}
if ($start+$posts_per_page < $total_records && $start >= 0)
{
$sum = $start + 5;
if ($start == 0){
echo "$start - <a href=".$_SERVER['PHP_SELF']."?start=".($start + $posts_per_page)."> $sum => </a>";
}
else
{
echo " -<a href=".$_SERVER['PHP_SELF']."?start=".($start + $posts_per_page)."> $sum => </a>";
}
}
}
?>
can anyone explain me this code
(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
|