•
•
•
•
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,610 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,500 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: 1044 | Replies: 7 | Solved
![]() |
•
•
Join Date: Jul 2007
Posts: 39
Reputation:
Rep Power: 2
Solved Threads: 1
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');
?>•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
if (!isset($pagenum))
{
.....
}
save a bit
$previous = $pagenum-1;
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
}
{
.....
}
save a bit
php Syntax (Toggle Plain Text)
if ($pagenum != 1) { echo " <a href='index.php?pagenum=1'> <<-First</a> "; echo " ";
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
}
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
•
•
Join Date: Jul 2007
Posts: 39
Reputation:
Rep Power: 2
Solved Threads: 1
•
•
•
•
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.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- pagination and search (PHP)
- PHP Search pagination problem (PHP)
- search and pagination (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP and MySQL Stored Procedure Exec Problem
- Next Thread: Send message


Linear Mode