Solved

PHP pagination

Posted on 2011-09-09
5
434 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 82

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

26 Experts available now in Live!

Get 1:1 Help Now