Forum
07:47
17/04/2011
Couldn t execute query.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
-------------coding----------
<html>
<body>
<table id="listdt" class="scroll"></table>
<div id="pagerdt" class="scroll" style="text-align:center;"></div>
<script src="datatype.js" type="text/javascript"> </script>
<script>
jQuery("#listdt").jqGrid({
//url:'server.php?q=2',
datatype : function (pdata) {
$.ajax({
url:'server.php?q=2',
data:pdata,
dataType:"json",
complete: function(jsondata,stat){
if(stat=="success") {
var thegrid = jQuery("#listdt")[0];
thegrid.addJSONData(eval("("+jsondata.responseText+")"))
}
}
});
},
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right", editable:true,editrules:{number:true,minValue:100,maxValue:350}},
{name:'tax',index:'tax', width:80, align:"right",editable:true,edittype:"select",editoptions:{value:"IN:InTime;TN:TNT;AR:ARAMEX"}},
{name:'total',index:'total', width:80,align:"right",editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"} },
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
imgpath: gridimgpath,
pager: jQuery('#pagerdt'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"Data type as function Example",
cellEdit: true
}).navGrid('#pagerdt',{edit:false,add:false,del:false});
</script>
<?php
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect("localhost","root","")
or die("Connection Error: " . mysql_error());
mysql_select_db("testjquery") or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/1);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[id];
$responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
$i++;
}
echo json_encode($responce);
?>
</body>
</html>
Most Users Ever Online: 715
Currently Online:
40 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66