Home arrow JavaScript arrow Page 3 - Building a Page Controller with the jQuery Quick Pagination Plug-in
JAVASCRIPT

Building a Page Controller with the jQuery Quick Pagination Plug-in


Welcome to the final installment of the series that introduces you to the jQuery Quick Pagination plug-in. Comprised of five parts, this series takes an in-depth look at the most useful features provided by this jQuery add-on and shows you how to use it either for splitting up hard-coded HTML elements, such as paragraphs and images in chunks of readable data, or for paginating sets of database records.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 3
December 31, 2009
TABLE OF CONTENTS:
  1. · Building a Page Controller with the jQuery Quick Pagination Plug-in
  2. · Review: web application source code so far
  3. · Building a simple page controller in PHP
  4. · Paginating user-related data

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building a Page Controller with the jQuery Quick Pagination Plug-in - Building a simple page controller in PHP
(Page 3 of 4 )

While its name may sound somewhat intimidating, a PHP page controller is nothing but a simple script that separates the server-side processing part from the output that it produces. In this particular case, I'm going to use a controller like this first for fetching the set of users-related rows stored on the associated MySQL, and then for displaying the data on the browser.

The page controller will be implemented within a file called "content.php," and will look like this:

(content.php)

 

<?php

 

// include dependencies

require_once 'MySQLAdapter.php';

require_once 'MySQLAdapterException.php';

 

// fetch users from the database

try

{

$db = MySQLAdapter::getInstance(array('host', 'user', 'password', 'test'));

$db->query('SELECT * FROM users');

$users = array();

while ($user = $db->fetch())

{

$users[] = $user;

}

}

// catch exceptions

catch (Exception $e)

{

echo $e->getMessage();

exit();

}

?>

<div id="content">

<h2>User Details</h2>

<div id="users">

<?php foreach ($users as $user):?>

<div>

<p><strong>First Name: </strong><?php echo $user->fname;?></p>

<p><strong>Last Name: </strong><?php echo $user->lname;?></p>

<p><strong>Email Address: </strong><?php echo $user->email;?></p>

</div>

<?php endforeach?>

</div>

</div>

There you have it. As you can see above, first the page controller uses an instance of the previous MySQL abstraction class to fetch all of the users existing in the database, and then displays this data formatted as HTML divs. While it's fair to stress that in this case both application logic and visual presentation rest in the same file, a page controller handles both layers separately, which is much cleaner than using a quick and dirty transcription script.

So far, so good. At this stage, the "content.php" file shows all of the records contained in the pertinent "users" MySQL table. So, what's the next step? Well, it's necessary to use the Quick Pagination plug-in to paginate those records and assemble the previous header, content and footer sections into a single web page.

All of these tasks will be accomplished in the next section. So click on the link below and read the next few lines.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials