[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP pagination

Posted on 2011-09-09
5
Medium Priority
?
463 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 84

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 2000 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 111

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …
Suggested Courses

649 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