I needed to paginate my article section at my site so that i wont have 20 paragraphs page, now when I tried this on LOCALHOST i encountered no problem at all. But when I uploaded it on my server, the pagination doesn't work. I think the problem here is about the global variables, but im not sure and I dont know how to fix it. Here's my code:

<?php
$pagenum = $_GET['pagenum'];
$pagetitle = 'article Sections';
$active = '2';
include('../includes/header.php');
$dbcnt = mysql_connect("localhost", "xxxxxx", "xxxxx"); 
mysql_select_db("articles");
	
echo '<!-- content-wrap starts here -->
	<div id="content-wrap">	'; 
include('../includes/sidebar.php');
echo '<div id="main">';
			//This checks to see if there is a page number. If not, it will set it to page 1 
	if (!(isset($pagenum))) 
	{ 
	$pagenum = 1; 
	} 

	//Here we count the number of results 
	//Edit $data to be your query 

			$data = mysql_query("SELECT * FROM dlink");
			$rows = mysql_num_rows($data);
			
			//This is the number of results displayed per page 
$page_rows = 4; 

//This tells us the page number of our last page 
$last = ceil($rows/$page_rows); 

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 
			//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM dlink $max") or die(mysql_error());
			// Query the database
			while ($row = mysql_fetch_assoc($data_p)) {
				echo '<div class="box">';
				echo '<h1>' .$row['downName'].'</h1>';
				echo '<p>Added on: <cite>'.$row['downTime'].'<cite></p>';
				echo '<img src='.$row['downImg'].' width=140 height=110 class="dimg" /><p style="text-indent:1px;">'.$row['downDes'].'</p>';
				echo '<br clear=none/><p class=comments align-right>Download link:<a href='.$row['downLink'].' target="_self">Download link</a></p>';
				echo '</div><div class="boxBottom"><img src="http://ivatanako.000webhost.info/images/block-bottom-bg.jpg" alt=""></div>';
			}
echo '<div class="box"><p class=comments align-right>';

// This shows the user what page they are on, and the total number of pages
echo " Page $pagenum of $last ";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='index.php?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
} 


//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='index.php?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='index.php?pagenum=$last'>Last ->></a> ";
} 
echo '</div><div class="boxBottom"><img src="http://xxx.com/images/block-bottom-bg.jpg" alt=""></div>';
// end all div
echo '</div></div>';			
include('../includes/footer.php');
?>

is there any errors? what exactly is happening?

Member Avatar for fatihpiristine

if (!isset($pagenum))
{
.....
}


save a bit

if ($pagenum != 1) 
{
echo " <a href='index.php?pagenum=1'> <<-First</a> ";
echo " ";

$previous = $pagenum-1;
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
}

is there any errors? what exactly is happening?

The problem is, is that the second page is not showing. The code works well on testing at localhost but when i uploaded it on webserver, it doesnt work.

is the url changing when a next or prev link is pressed? is the script outputting the right numbers to the next and prev links? i copied the script, made a few minor changes (mysql connect info, table names, ect..) so it would work for me, and i had no problems with it.

is the url changing when a next or prev link is pressed? is the script outputting the right numbers to the next and prev links? i copied the script, made a few minor changes (mysql connect info, table names, ect..) so it would work for me, and i had no problems with it.

It is changing, it was also working on localhost, I just dont know why doesn't it work on my website.

can you give me the url of the page so i can see what is happening for myself.

can you give me the url of the page so i can see what is happening for myself.

Thank you for the time. I was able to fix it by rewriting the whole code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.