|
1 |
<?php <br />include('connections/dbconfig.php');<br /><br />$page = $_GET['page']; // get the requested page<br />$limit = $_GET['rows']; // get how many rows we want to have into the grid<br />$sidx = $_GET['sidx']; // get index row - i.e. user click to sort<br />$sord = $_GET['sord']; // get the direction<br />if(!$sidx) $sidx =1;<br />// connect to the database<br />$db = mysql_connect($dbhost, $dbuser, $dbpassword)<br />or die("Connection Error: " . mysql_error());<br /><br />mysql_select_db($database) or die("Error conecting to db.");<br />$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");<br />$row = mysql_fetch_array($result,MYSQL_ASSOC);<br />$count = $row['count'];<br /><br />if( $count >0 ) {<br /> $total_pages = ceil($count/$limit);<br />} else {<br /> $total_pages = 0;<br />}<br />if ($page > $total_pages) $page=$total_pages;<br />$start = $limit*$page - $limit; // do not put $limit*($page - 1)<br />$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";<br />$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());<br /><br />$responce->page = $page;<br />$responce->total = $total_pages;<br />$responce->records = $count;<br />$i=0;<br />while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br /> $responce->rows[$i]['id']=$row[id];<br /> $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row<!-- -->);<br /> $i++;<br />} <br />echo json_encode($responce);<br /><br />?> |
yes i have… this is the html:
…
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
jQuery(document).ready(function(){
jQuery(“#list”).jqGrid({
url:'example.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
colModel :[
{name:'invid', index:'invid', width:55},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:100, align:'right'},
{name:'total', index:'total', width:100, align:'right'},
{name:'note', index:'note', width:150, sortable:false}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'invid',
sortorder: 'desc',
viewrecords: true,
caption: 'My first grid'
});
});
…
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top