<?php
include_once('config.inc.php');
$link = mysqli_connect(
db_default_host,
db_default_user,
db_default_password,
db_default_database
) OR die(mysqli_error());
$sql = "SELECT
CustomerID,
CompanyName,
ContactName,
City,
Country
FROM customers";
// if table column names are written underscored, then they will be automatically
// converted to camel-case notation for php access
// the northwind field names are usually written camel-cased.
$pageSize = ($_GET["s"]?(int)$_GET["s"]:2);
$result = mysqli_query($link, $sql);
$dataObject = new QDataObject::getInstance($result, $link);
$dataObject->byPage((int)$_GET["p"],$pageSize);
$html = '<table border="1" cellspacing="2" cellpadding="2">';
$html.='<thead>';
$html.='<tr>';
foreach($dataObject->getFieldNames() as $columnName) {
$html.='<th>';
$html.=$columnName;
$html.='</th>';
}
$html.='</tr>';
$html.='</thead>';
$html.='<tbody>';
for($i=0;$i<$dataObject->getAmountOfRows();$i++) {
$html.='<tr>';
foreach($dataObject->getFieldNames() as $columnName) {
$html.='<td>';
$get = "get".$columnName;
$data = $dataObject->$get($i);
$html.= empty($data) ? ' ':$data;
$html.='</td>';
}
$html.='</tr>';
}
$html.='</tbody>';
$html.='<tfoot>';
$html.='<tr>';
$html.='<td colspan="'.$dataObject->getNumFields().'">';
$html.=$dataObject->getNumRows().' records ';
if($dataObject->getActivePage()>1) {
$html.='<a href="?p='.($dataObject->getActivePage()-1).'&s='.$pageSize.'"><</a>';
}
$html.='<b>'.($dataObject->getActivePage()).'</b>';
if($dataObject->getActivePage() < $dataObject->getNumOfPages()) {
$html.='<a href="?p='.($dataObject->getActivePage()+1).'&s='.$pageSize.'">></a>';
}
$html.='</td>';
$html.='</tr>';
$html.='</tfoot>';
$html .= '</table>';
echo $html;
|