Solved

PHP pagination

Posted on 2011-09-09
5
435 Views
Last Modified: 2012-05-12
I've inherited at php site with a dynamic pagination issue and I do not know how to debug. Help!

http://passyourdrugtest.com/newsite/testimonials.html?page=2
0
Comment
Question by:webdork
5 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36515100
It's got no issue, it doesn't page.  The code is ignoring the 'page=x' part and just bringing up the same page all the time.  The page code needs to multiplied times the page size and put in a LIMIT statement as the starting point for that page.  Similar to below:
SELECT * FROM tbl LIMIT 0,30;  # page 0 rows 1-30
SELECT * FROM tbl LIMIT 30,30;  # page 1 rows 31-60
SELECT * FROM tbl LIMIT 60,30;  # page 2 rows 61-90
SELECT * FROM tbl LIMIT 90,30;  # page 3 rows 91-120

Open in new window

0
 
LVL 13

Expert Comment

by:F Igor
ID: 36515226
It seems your page is a static HTML (testimonials.html) content and does not page in any way.
Dou you own the original site? Maybe the pages you are getting are exported
from the HTML content generated at the original site, and is not the source code.

Where are the rest of pages?
Are you generated with a database backend or with plain HTML?



0
 

Author Comment

by:webdork
ID: 36515267
I dont think its static html. I think the php is using slug to generate friendly urls.  Is the controlling code in the attached?
<?php defined('SYSPATH') OR die('No direct access allowed.');

class Testimonials_Controller extends Template_Controller {

	// Set the name of the template to use
	public $template = 'frontend/site';
	public $per_page = 80; //Number of testimonials to show per page

	public function index()
	{
		$page_num = $this->input->get('page', 1);
		$offset   = ($page_num - 1) * $this->per_page;
 
		$_testimonials = ORM::factory('testimonial')->orderby(array('id'=>'DESC'))->limit($this->per_page, $offset)->find_all();
		$pages = Pagination::factory(array
		(
    		'style' => 'digg',
    		'items_per_page' => $this->per_page,
    		'query_string' => 'page',
    		'total_items' => ORM::factory('testimonial')->count_all()
		));


		$this->template->page_title = 'Testimonials - Page ' . $page_num;

		$this->template->content = new View('frontend/testimonials');
		$this->template->content->testimonials = $_testimonials;
		$this->template->content->pagination = $pages;

	}



	public function view($id, $slug) {
		$_testimonial = ORM::factory('testimonial')->where(array('id'=>$id))->find();

		$this->template->page_title = $_testimonial->title;

		$this->template->content = new View('frontend/testimonial');
		$this->template->content->testimonial = $_testimonial;
		
	}


}

Open in new window

0
 
LVL 13

Accepted Solution

by:
F Igor earned 500 total points
ID: 36515314
Ok, lookin at your code i see that the Page title should be changing to
"Testimonials - Page 1" using the "page=N" parameter from GET.

But i see no change in the title when change the page=2 parameter to page=3
(It always shows "Testimonials - Page 1")

(Are you useing CodeIgniter ?)
Maybe the server losts the "GET" variables when it rewrites the page to ".html",
or your code at line 11 is not working as you wish:

$page_num = $this->input->get('page', 1);

Open in new window





You can add a debug at this point:

$page_num = $this->input->get('page', 1);

die("The current page is $page_num");

Open in new window


And see if the message changes when you change the page number.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36516033
The classic answer to PHP pagination is available from SitePoint here.
http://www.sitepoint.com/perfect-php-pagination/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now