hi fellas, i've read all the tutorials about
Next/Prev buttons thing, but i really can't get it to work properlly, i would be most grateful if someone could help me out here! 😉
here is the code i use now, which doesn't work, cause when i click on the next button, no rows are return:
<BODY bgColor="#FFFFCC">
<?php
$DBhost = "localhost";
$DBuser = "shiningone";
$DBpass = "crystal";
$DBName = "shiningone";
mysql_connect($DBhost,$DBuser,$DBpass);
mysql_select_db("$DBName");
if (empty($offset) || $offset < 0) {
$offset=1;
}
$limit = 50;
$numresults = mysql_query("SELECT * FROM annons WHERE category = '$kategori' AND location = '$landskap'");
$totalrows = mysql_num_rows($numresults);
$begin = ($offset+1);
$end = ($begin+($limit-1));
if ($end > $totalrows) {
$end = $tatalrows;
}
// get results
if ($landskap == alla) {
$result=mysql_query("SELECT * FROM annons WHERE category = '$kategori' ORDER BY date desc,id desc LIMIT $offset,$limit");
} else {
$result=mysql_query("SELECT * FROM annons WHERE category = '$kategori' AND location = '$landskap' ORDER BY date desc,id desc LIMIT $offset,$limit");
}
// now you can display the results returned
while ($row=mysql_fetch_array($result)) {
print ("<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>");
print ("<td width=150 align=left bgcolor=#FFE3FF>");
print ("<font size=\"2\" face=\"verdana\">");
print (" ");
?>
<a href="annons_id.php?id=<?php print $row["id"]; ?>"><u><?php print $row["name"]; ?></u></a>
<?
print ("</td>");
print ("<td width=315 align=left bgcolor=#FFE3FF>");
print ("<font size=\"2\" face=\"verdana\">");
print $row["annonsrubrik"];
print ("<td width=100 align=right bgcolor=#FFE3FF>");
print ("<font size=\"2\" face=\"verdana\">");
print $row["date"];
print (" ");
print ("</td></tr><tr><td height=1>");
print ("</TD></TR></table>");
}
// Calculate total number of pages in result
$pages = intval($totalrows/$limit);
// $pages now contains total number of pages needed unless there is a remainder from division
if ($totalrows%$limit) {
// has remainder so add one page
$pages++;
}
// Now loop through the pages to create numbered links
// ex. 1 2 3 4 5 NEXT
for ($i=1;$i<=$pages;$i++) {
// Check if on current page
if (($offset/$limit) == ($i-1)) {
// $i is equal to current page, so don't display a link
echo "$i ";
} else {
// $i is NOT the current page, so display a link to page $i
$newoffset=$limit*($i-1);
}
}
// Check to see if current page is last page
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
// Not on the last page yet, so display a NEXT Link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
?>