Solved

PHP pagination

Posted on 2011-09-09
5
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

696 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