<?php
if(empty($_SERVER["HTTP_X_REQUESTED_WITH"])=="XMLHttpRequest") {
header("Location:sample2b.php");
}
include_once('config.inc.php');
//provide your connection data here
$link = mysqli_connect(
'db_default_host',
'db_default_user',
'db_default_password',
'northwind'
) 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"]:10);
$result = mysqli_query($link, $sql);
$dataObject = new QDataObject::getInstance('mysqli',$result, $link);
$dataObject->byPage((int)$_GET["p"],$pageSize);
$html = '<table border="1" cellspacing="2" cellpadding="2" width="100">';
$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 class="'.($i%2?'odd':'even').'">';
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.='<th colspan="'.$dataObject->getNumFields().'">';
$html.=$dataObject->getNumRows().' records ';
if($dataObject->getActivePage()>1) {
$html.='<a href="#" onclick="$.get(\'sample2b1.php?p='.($dataObject->getActivePage()-1).'&s='.$pageSize.'\',function(data){$(\'#select\').html(data);});"><</a>';
}
$html.='<b>'.($dataObject->getActivePage()).'</b>';
if($dataObject->getActivePage() < $dataObject->getNumOfPages()) {
$html.='<a href="#" onclick="$.get(\'sample2b1.php?p='.($dataObject->getActivePage()+1).'&s='.$pageSize.'\',function(data){$(\'#select\').html(data);});">></a>';
}
$html.='</th>';
$html.='</tr>';
$html.='</tfoot>';
$html .= '</table>';
$html.='';
$html .= "
<script>
var np=".$dataObject->getNumOfPages().";
var lx=1;
var ly=1;
w = $('#select').width();
$('.slider').css('width', w+'px');
$('.slider').Slider(
{
accept : '.indicator',
opacity: 0.8,
fractions: ".$dataObject->getNumOfPages().",
onSlide: function(procx, procy, x, y) {
$('#indicator1').css('left', x+'px');
$('#indicator2').css('left', x+'px');
lx=Math.ceil((".$dataObject->getNumOfPages()."/w)*x);
},
onChange : function(){
$.get('sample2b1.php?p='+lx+'&s=".$pageSize."',function(data){\$('#select').html(data);});
}
});
</script>
";
echo $html;
|