Search

Thursday 21 January 2010

Simple php tabulation helper class

This class would allow you to grab your required 'view' of data from a given query by simply providing the query and changing your page number each time. The function does not provides any view it only has one print function which could be used for testing or could be overwritten to serve your purpose.

The helper class requires the database class in my previous post.

The tabulation class file could be downloaded from http://nasaralla.googlecode.com/files/tabulation.php

and you also need this database.php: http://nasaralla.googlecode.com/files/database.php
____________________________________________
//in your code you need to include tabulation.php as follows
include("tabulation.php");
//next you call the constructor and set the query only once and also the page limit
$tab = new Tabulation("select * from cutpriceh", 10);
//make sure you do not put a semi-colon (;) at the end
//then you need to set from which database (MySQL) you are bringing in the data
$tab->setDBParam("localhost","cutprice","root","");
//and you run the getResults function which given the page number would return the result set //as well as store the result set in a private variable ...
$results = $tab->getResults(3);
//Finally you could use the build in print table function to print your page of values
$tableIndex = array('Hotel','City');
$tab->printResults($tableIndex);
//the function takes in an array of database field names and prints only those fields
____________________________________________

No comments:

Post a Comment