Jump to content

"Previous - Next Page" Script not working


CSkovholm

Recommended Posts

Hey there :-) I'm having some trouble with my script here, as stated above, it's supposed to be a small script that provides you with the oppertunity to go to the next or previous page of a MySql result page. I've set the limit to 1, just to test it. The table i'm retrieving from has 3 rows inserted.

 

The script returns following errors:

 

ChristianPages:(3)  [1]

Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 129

2

Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 129

3

Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 153

>>

Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 155

  Last >>

 

And the script itself:

<?php

require "include/db.php";

#
$sql = "SELECT * FROM brugere";
#
$query = mysql_query($sql);
#
$total_results = mysql_num_rows($query);
#
$limit = "1"; //limit of archived results per page.
#
$total_pages = ceil($total_results / $limit); //total number of pages
#
if (empty($page))
#
{
#
$page = "1"; //default page if none is selected
#
}
#
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB
#

#
$query = "SELECT * FROM brugere LIMIT $offset, $limit";
#
$result = mysql_query($query);
#
//This is the start of the normal results...
#

#
while($row=mysql_fetch_array($result))
#
{
#
echo $row['bruger_navn'];
#
}
#
#

#

#
// This is the Previous/Next Navigation
#
echo "<font face=Verdana size=1>";
#
echo "Pages:($total_pages)  "; // total pages
#
if ($page != 1)
#
{
#
echo "<a href=$PHP_SELF?page=1><< First</a>   "; // First Page Link
#
$prevpage = $page - 1;
#
echo " <a href=$PHP_SELF?page=$prevpage><<</a> "; // Previous Page Link
#
}
#
if ($page == $total_pages)
#
{
#
$to = $total_pages;
#
}
#
elseif ($page == $total_pages-1)
#
{
#
$to = $page+1;
#
}
#
elseif ($page == $total_pages-2)
#
{
#
$to = $page+2;
#
}
#
else
#
{
#
$to = $page+3;
#
}
#
if ($page == 1 || $page == 2 || $page == 3)
#
{
#
$from = 1;
#
}
#
else
#
{
#
$from = $page-3;
#
}
#

#
for ($i = $from; $i <= $to; $i++)
#

#
{
#
if ($i == $total_results) $to=$total_results;
#
if ($i != $page)
#
{
#
echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
#
}
#
else
#
{
#
echo "<b><font face=Verdana size=2>[$i]</font></b>";
#
}
#
if ($i != $total_pages)
#
echo " ";
#
}
#
if ($page != $total_pages)
#
{
#
$nextpage = $page + 1;
#
echo " <a href=$PHP_SELF?page=$nextpage>>></a> "; // Next Page Link
#
echo "   <a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link
#
}
#
echo "</font>";
#

#
// This is the end of the Previous/Next Navigation

?>

Link to comment
https://forums.phpfreaks.com/topic/199107-previous-next-page-script-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.