[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP pagination

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 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
Course of the Month18 days, 6 hours left to enroll

829 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