Hi i have written a php code to sort my search results with a previous/next option.
I have changed the settings so that there is a maximum of 5 results for each result page. If there are more results that you can click the next (in dutch called "volgende") button to go to the next page.
I have put 10 items in my database with the word ("armandleg"). When i search for this word it shows the first 5 results perfectly on the first result page and it also automatically makes a second page for the next 5 result (so in total there have to be 10 results).
There comes the problem: when i click on the next button it dont show the next 5 results but shows my "no-result" page who is printing that there are no results...
How is that possible because im sure that there are 10 items who match the searh term...
am i doing something wrong ?? i really tried everything but i cant find it. Please help me !!!!
This is my code:
<?php
include("config2.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$extrazoek = $_POST['extrazoek'];
$zoekterm = $_POST['zoekterm'];
// Variables
if(is_numeric($_GET['max'])) $max = $_GET['max'];
if(is_numeric($_GET['start'])) $start = $_GET['start'];
if (empty($max)) $max = 5; // $max is the maximum number of results per page
if (empty($start)) $start = 0; // This is the number to start the query at the right location [DO NOT EDIT]
// Calculate some stuff
$end = $start + $max; // This is for the query, gives the number for the LIMIT
$prev = $start - $max; // This number is for $start in the Previous-hyperlink
$next = $end; // This number is for $start in the Next-hyperlink
// Select everything from the table
switch ($_POST['extrazoek']) {
case "zoekalles":
$query = "SELECT * FROM artikelen WHERE omschrijving LIKE '%$_POST[zoekterm]%' ORDER BY id DESC";
break;
case "zoekmannen":
$query = "SELECT * FROM artikelen WHERE omschrijving LIKE '%$_POST[zoekterm]%' AND doelgroep='mannen' ORDER BY id DESC";
break;
case "zoekvrouwen":
$query = "SELECT * FROM artikelen WHERE omschrijving LIKE '%$_POST[zoekterm]%' AND doelgroep='vrouwen' ORDER BY id DESC";
break;
}
// Number of rows + count from $query
$res = mysql_query($query) or trigger_error(mysql_error());
$count = mysql_num_rows($res);
$query .= " LIMIT $start, $max";
$res = mysql_query($query) or trigger_error(mysql_error());
if (empty($count))
{
include("geenresultaat.php");
}
else
{
?>
<table>
<?php
while ($row = mysql_fetch_array($res))
{
// Show the results
?>
inhoud van de tabel
<?php
}
?>
</table>
<?php
// Check if $prev is higher than or equal to 0, if so add the Previous-hyperlink
if ($prev >= '0')
{
echo "[<a href=\"artikelresultaat2.php?start=$prev&max=$max\">« vorige</a>]\n";
} else {
echo "« vorige\n";
}
// Calculate on which page we are
$thispage = ceil($start/$max+1);
// If $count[0] is higher than $max, show the pagenumbers
if ($count > $max)
{
// Calculate the amount of pages
$total = ceil($count/$max);
for($i=0;$i<$total;$i++)
{
// The number to show has to be $1+1 (because $i starts with 0)
$number = $i+1;
// $start has to be $i * $max
$start = $i*$max;
// If thispage is equal to the number, the link has to be bold
if ($thispage == $number)
{
echo "<strong>[<a href=\"artikelresultaat2.php?start=" . $start . "&max=" . $max . "\">" . $number . "</a>]</strong>\n";
} else {
echo "<a href=\"artikelresultaat2.php?start=" . $start . "&max=" . $max . "\">" . $number . "</a>\n";
}
}
}
// If $count[0] is higher than $next, show the hyperlink
if ($count > $next)
{
echo "[<a href=\"artikelresultaat2.php?start=$next&max=$max\">volgende »</a>]\n";
} else {
echo "volgende »\n";
}
echo "</p>\n";
}
?>