Old 12-14-2007   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Registered User
 
Join Date: Dec 2007
Posts: 1

Send a message via AIM to verbazon
Biorust MySQL LIMIT/Pagination Tutorial

I'm trying to implement your tutorial into my news system to paginate my news but it's not working...

The only thing that works is it's correctly limiting my news posts to display 3 at once. But the previous and next page links don't work. They show up as
http://mysite.com/index.php?start=3 (Previous Page)
http://mysite.com/index.php?start=-3 (Next Page)

and they don't do anything when clicked on. How can I make it so they display a new page with the next 3 news posts? Here is the code:

PHP Code:
<?php
if ( $_GET['number'] == NULL ){
$limit 3;
} else {
$limit $_GET['number'];
}

if (
$_GET['page']==NULL){
$start 0;
} else {
$start $_GET['page'];
}

// the if above, states that if the variable in the URL named page has a value, $start will be set to it, otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default.

if($_GET['page'] < 0){
header("Location: http://mysite.com/index.php?page=0&limit=".$limit);
}

// this if above checks that the start variable isn't negative, because if it is, our script will screw up. If it finds that it is, it redirects to the default page where the start is 0.


$query mysql_query("SELECT * FROM `mytable` ORDER BY `id` DESC LIMIT ".$start.",".$limit.";") or die('MySQL Error: ' mysql_error());
while(
$row mysql_fetch_array($query))
{
     echo 
'<h2>' $row['title'] . '</h2>
        

         <b><span style="margin-left:5px;" />Author: </b>' 
$row['author'] . '

         <b><span style="margin-left:5px;" />Date: </b>' 
$row['date'] . '
         <p>' 
nl2br($row['content']) . '</p><hr />';
}

$previous $start $limit;
$next $start $limit;
echo 
"<div align='center'>
     <a href='http://mysite.com/index.php?start="
.$previous."'>Previous Page</a> -
     <a href='http://mysite.com/index.php?start="
.$next."'>Next Page</a>
         </div>
"
;

// the set of statements above displays the previous and next page links
?>
Thanks for the help!
verbazon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 3 Weeks Ago   #2 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 1

Here is an article on pagination. It even provides a function you can copy and paste and you set.
WebDeveloperWannaBe - A Website for aspiring Web Developers
tallercreativo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://forums.biorust.com/html-php-asp-js/6985-biorust-mysql-limit-pagination-tutorial.html
Posted By For Type Date
BioRUST.com :: PHP, ASP, & MySQL Tutorials This thread Refback 12-16-2007 02:29 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
BioRust Tutorial - Form Validation Class - Missing File phill2000star HTML / PHP / ASP / JS 3 12-20-2007 12:33 AM
BioRust Tutorial Question Sm86 Adobe Photoshop 3 03-04-2006 11:03 PM
Biorust Reaches Tutorial #101! Man1c M0g Announcements 2 08-24-2005 09:18 PM
Biorust first 3d tutorial: maybe Milkdrop BioRUST Specific Threads 13 09-01-2004 06:15 PM
biorust FIRE tutorial d2raptor Adobe Photoshop 3 07-19-2004 10:32 PM


All times are GMT +1. The time now is 11:34 PM.
Content Relevant URLs by vBSEO 3.2.0 RC7

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT