Current location: Hot Scripts Forums » Programming Languages » PHP » Pagination Error


Pagination Error

Reply
  #1 (permalink)  
Old 01-07-10, 12:22 AM
Scriptex Scriptex is offline
New Member
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Pagination Error

For some reason when this code executes it's been displaying no results, and just a page number. I have the exact same setup minus the pagination code, and it's working fine I'l in include the links just for reference ~~
FarCry - Mollio (broken with pagination included)
Our Movies Organized By Year (w/out pagination)
and here is my coding that is giving me the error

PHP Code:

<?php


$result 
mysql_query("SELECT * FROM movies ORDER BY year");

$page $_GET['page'];
    echo 
"<ul>";

$pagedResults = new Paginated($result100$page);

while(
$row $pagedResults->fetchPagedRow()) 
    {    
//when $row is false loop terminates
  
echo "<li>";
  echo 
$row['title'];
  echo 
" " $row['year'];
  echo 
"<li>";
  echo 
"<br />";
  echo 
'<a href="quotes.php?movieid=' $row['id'] . '">' 'Click to view quote for '$row['title'] . '</a>';
  echo 
"<p>" "</p>";
  
  }

      echo 
"</ul>";
        
//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults->setLayout(new DoubleBarLayout());
echo 
$pagedResults->fetchPagedNavigation();
mysql_close($con);
?> 
        
            
        
            
            <div id="footer">
            <p>A note here to go in the footer</p>
            <p><a href="#">Contact Us</a> | <a href="#">Privacy</a> | <a href="#">Links</a></p>
            </div>
            
        </div>
        
        
    </div>
    
</div>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 01-11-10, 04:44 AM
dgreenhouse's Avatar
dgreenhouse dgreenhouse is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: San Francisco
Posts: 457
Thanks: 0
Thanked 3 Times in 3 Posts
I'm not familiar with nor do you show the basis of the class: Paginated.

But...

I can tell that if the class requires a full result set (as shown by your select statement) to operate properly, then it is possibly flawed and inefficient.

A proper pagination routine should be based on the page number requested plus the number of "pre-defined or user-selectable" results to be displayed per page.

i.e.
SELECT * FROM movies LIMIT 0,100
- or -
SELECT * FROM movies LIMIT 100 OFFSET 0

You could then use the page# requested to calculate the OFFSET.

i.e.
define("RESULT_LIMIT",100);
$page = isset($_GET['page']) ? (int) $_GET['page'] : 0; // ensure we get a numeric
$page = $page * RESULT_LIMIT; // set the page offset
$sql = "SELECT * FROM movies LIMIT $page OFFSET ".RESULT_LIMIT;
// Output pagination at top
// Output results in a loop or from a module...
// Output pagination at bottom

There are numerous pagination classes and functions available on the net that will work for you.

A little pagination helper that I've used a few times in the past can be found here:
php easy :: pagination scripts set
It has a fairly small footprint and easy to use.
There are three functions included that you can pick from that use different pagination styles.
There is also a css file included that will style the pagination output.
You'll probably need to tinker a bit with it.

But as stated, there are many other (and better) "paginators" available online.

Hope that helps.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and MSSQL tutorials? scott2500uk C/C++ 8 05-11-09 02:33 AM
[SOLVED] 500 Internal Server Error - Please help Dawn Perl 15 07-08-08 11:08 AM
Syntax Error Nikas Database 4 05-15-08 10:48 AM
server error in ' / ' application vikkygupta2005 ASP.NET 1 11-10-06 06:07 AM
ASP upload prob minority ASP 1 06-27-05 08:35 AM


All times are GMT -5. The time now is 08:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.