 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
itp
Joined: 01 Jul 2007 Posts: 10
|
Posted: Thu Jul 05, 2007 4:48 am Post subject: Structures/DataGrid example with SQL statement |
|
|
OK, I got the basic Structures/DataGrid example working with paging and added columns. Now I want to add a more complicted SQL statement (select ... where ... group by... order by...). Can you point me in the right direction?
thanks for your help!!!!
| Code: |
<html>
<head>
<link rel="stylesheet" type="text/css"
href="homes.css" />
<h4>Add additional columns to the grid with Structures_DataGrid_Column() and getCurrentRecordNumberStart()</h4>
<?php
/* Includes */
require_once "PEAR.php";
define("DB_DATAOBJECT_NO_OVERLOAD",true); /* May be required for some versions of PHP4 */
require_once "DB/DataObject.php";
require_once "Structures/DataGrid.php";
/* Catch any errors*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
PEAR::setErrorHandling(PEAR_ERROR_DIE);
/* function to format Row Number */
function formatRowNumber($params, $recordNumberStart)
{
return $params['currRow'] + $recordNumberStart;
}
/* Database and DataObject setup */
$dataobjectOptions = &PEAR::getStaticProperty("DB_DataObject","options");
$dataobjectOptions["database"] = "mysqli://root:@localhost/homes";
$dataobjectOptions["proxy"] = "full";
class DataObject_Fruits extends DB_DataObject
{
// var $__table = "listings where code =100"; - no... syntax error,
// var $__table = "select * from listings where code =100"; - no... syntax error,
var $__table = "listings";
var $code;
var $town;
var $price;
var $bedrooms;
}
/* Instantiate data grid*/
$dataobject = new DataObject_Fruits();
$datagrid =& new Structures_DataGrid(10); /* table 1: 10 rows per table */
/* Required in order to use the "fields" and "labels" options */
$datagridOptions["generate_columns"] = true;
/* The fields we want to display */
$datagridOptions["fields"] = array ("code", "town", "price");
/* Translate the fields names into user-friendly labels */
$datagridOptions["labels"] = array (
"town" => "Town",
"code" => "Code",
"price" => "Price"
);
/* Bind */
$bind = $datagrid->bind($dataobject, $datagridOptions);
/*Add a blank column. The first parameter that is passed to such a formatter function contains a currRow value with the row number per page. */
$datagrid->addColumn(
new Structures_DataGrid_Column(
'This Column is <br>intentionally left blank', // column header
null,
null,
array('style' => 'text-align: center;'), // style
null,
null,
$datagrid->getCurrentRecordNumberStart()
));
/*Add a column containing the row number: The first parameter that is passed to such a formatter function contains
a currRow value with the row number per page. For calculating the row number relative to the whole table, you need
to take also the getCurrentRecordNumberStart() method into account. */
$datagrid->addColumn(
new Structures_DataGrid_Column(
'Seq. No.',
null,
null,
array('style' => 'text-align: right;'),
null,
'formatRowNumber',
$datagrid->getCurrentRecordNumberStart()
));
// catch error messages on bind
if (PEAR::isError($bind))
{
echo $test->getMessage();
}
/* Get a reference to the Renderer object */
$renderer =& $datagrid->getRenderer();
/* For the <table> element : */
$renderer->setTableAttribute("class", "fruits");
/* For every odd <tr> elements - this links back to the CSS stylesheet*/
$renderer->setTableOddRowAttributes(array ("class" => "odd"));
/* For every even <tr> elements - this links back to the CSS stylesheet*/
$renderer->setTableEvenRowAttributes(array ("class" => "even"));
/* Get and output HTML links and Output table */
$pagingHtml = $renderer->getPaging();
echo "<p>Pages : $pagingHtml</p>";
$datagrid->render();
/* list included files */
$included_files = get_included_files();
echo "<br>";
foreach ($included_files as $filename) {
echo $filename .'<br>';
}
?>
|
|
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1000
|
Posted: Thu Jul 05, 2007 10:33 am Post subject: Re: Structures/DataGrid example with SQL statement |
|
|
| itp wrote: | | OK, I got the basic Structures/DataGrid example working with paging and added columns. Now I want to add a more complicted SQL statement (select ... where ... group by... order by...). Can you point me in the right direction? |
DBDO offers several methods for this, c.p. the manual for details, e.g.:
http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject.groupby.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|