User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,277 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,174 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1043 | Replies: 7 | Solved
Reply
Join Date: Jul 2007
Posts: 39
Reputation: ivatanako is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ivatanako ivatanako is offline Offline
Light Poster

Pagination Help

  #1  
Nov 9th, 2007
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');
?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 71
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Pagination Help

  #2  
Nov 10th, 2007
is there any errors? what exactly is happening?
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Pagination Help

  #3  
Nov 10th, 2007
if (!isset($pagenum))
{
.....
}




save a bit
  1.  
  2. if ($pagenum != 1)
  3. {
  4. echo " <a href='index.php?pagenum=1'> <<-First</a> ";
  5. echo " ";
$previous = $pagenum-1;
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
}
Reply With Quote  
Join Date: Jul 2007
Posts: 39
Reputation: ivatanako is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ivatanako ivatanako is offline Offline
Light Poster

Re: Pagination Help

  #4  
Nov 10th, 2007
Originally Posted by kkeith29 View Post
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.
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 71
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Pagination Help

  #5  
Nov 10th, 2007
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.
Reply With Quote  
Join Date: Jul 2007
Posts: 39
Reputation: ivatanako is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ivatanako ivatanako is offline Offline
Light Poster

Re: Pagination Help

  #6  
Nov 10th, 2007
Originally Posted by kkeith29 View Post
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.
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 71
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Pagination Help

  #7  
Nov 10th, 2007
can you give me the url of the page so i can see what is happening for myself.
Reply With Quote  
Join Date: Jul 2007
Posts: 39
Reputation: ivatanako is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ivatanako ivatanako is offline Offline
Light Poster

Re: Pagination Help

  #8  
Nov 11th, 2007
Originally Posted by kkeith29 View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC