Solved

$_GET inside a PHP class

Posted on 2010-11-29
3
637 Views
Last Modified: 2012-05-10
I have a theoretical question about a class construction in PHP.

Let's say i want to build a pagination class and i want to handle user input inside the class
(buttons - Next, Prev). I imagine i would have to call the script again $PHP_SELF when pressing
next or Prev button, and then through $_GET display the required set of records, so can I
construct my script like this example:

 <html>
  ..  header etc.

 <?php
 require_once   'paginate.php';
   mypagination = new Page;  

   PAge->display();


 ?>

I mean, is it a common approach ?. Would it matter that new Page, would be executed each
time user clicks Next, Prev buttons ?
0
Comment
Question by:iskibinska
3 Comments
 
LVL 17

Assisted Solution

by:sweetfa2
sweetfa2 earned 100 total points
ID: 34235417
A lot of pages use a similiar option to this.

A lot of pages will refresh on a list change.

The other approach is to use ajax style processing to load prev/next in the background but requires more work at the client side in particular.
0
 

Accepted Solution

by:
ilnnlm earned 150 total points
ID: 34238158
You can create the "Page" object once and store it in a session variable. Like this you will have the current page stored in the object and you can call methods like "Page->Next()", "Page->Previous()" or "Page->GoTo()".

To store the object in a session variable you will need to use the functions "serialize()" & "unserialize()" refer to the manual here http://php.net/manual/en/function.serialize.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34239386
There is a canonical and definitive description of pagination here (feel free to ignore the popups, although they advertise good books):
http://articles.sitepoint.com/article/perfect-php-pagination

$_GET is one of the superglobals, so it is present in all namespaces and variable scopes.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

747 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

14 Experts available now in Live!

Get 1:1 Help Now