Friday, July 2, 2010

GridView like control for PHP

PHP class for generating an HTML table from a given MySQL query. The class can render the table columns with result column data using custom formats, with links and check boxes. The table listing may have pagination links.The presentation of the table and link styles are configurable using CSS.

Screenshot:

Usage:


<?php
$conn = mysql_connect("localhost", "username", "password");
mysql_select_db ("mysql_db");
if (!$conn) 
    {
        die('Could not connect: ' . mysql_error());
    }
//check the source code for detailed phpDoc style comments
$gridview = new GridView($conn, "SELECT * FROM sample");
$gridview->setAllowPaging(TRUE, "pg_class",2,"2,4,6,8,10");
$gridview->setAllowSorting(true);
$gridview->setAllowSearch(true,"LastName");
$gridview->setGridCaption("Grid Caption");
$gridProperties = array(
       array("ID","id",Type::Label,""),
       array("FN","FirstName",Type::Link,"www.{0}{1}.com:LastName,FirstName:{FirstName}"),
       array("LN","LastName",Type::Label,""),
       array("email","email",Type::Label,""),
       array("phone","phone",Type::Label,""),
       array("blog","blog",Type::Link,"::myblog"),
       array("comments","comments",Type::Label,""),
       array("yes/no","bool",Type::CheckBox,"")
       );
$gridview->setStyleID("gridView");
$gridview->setGridProperties($gridProperties);
$gridview->show();
?>

The source for this class can be downloaded from phpclasses