Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Error editing & displaying data
09/01/2012
03:09
Avatar
cheech74
Member
Members
Forum Posts: 10
Member Since:
31/12/2011
sp_UserOfflineSmall Offline

I have managed to create a basic grid, but i am now getting this error when trying to make the new data in editable cells save to the database – also the data is not being displayed in the grid anymore

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 '-10 , 10' at line 1
 
My php - 

<?php
$dbhost = xxxxxx.com';  $dbuser = 'xxxxxxxx';  $dbpassword = 'xxxxxx';  $dbdatabase = xxxxx;
 
$page = $_REQUEST['page'];  // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;

// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
mysql_select_db($dbdatabase) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
 $total_pages = ceil($count/$limit);
} 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.client_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);

?>

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxxxxx</title>
<link rel="stylesheet" type="text/css" href="timesheet_login.css">
<link rel="stylesheet" media="print" href="print.css" type="text/css">
<link rel="shortcut icon" href="oneline_logo.gif">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>


<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="scripts/js/jqModal.js" type="text/javascript"></script>
<script src="scripts/js/jqDnR.js" type="text/javascript"></script>

<script type="text/javascript">
$(function(){
  $("#list").jqGrid({
    url:'example.php',
    datatype: "json",

    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
     {name:'id',index:'id', width:55},
     {name:'invdate',index:'invdate', width:90,editable:true},
     {name:'name',index:'name asc, invdate', width:100},
     {name:'amount',index:'amount', width:80, align:"right",editable:true,editrules:{number:true}},
     {name:'tax',index:'tax', width:80, align:"right",editable:true,editrules:{number:true}},  
     {name:'total',index:'total', width:80,align:"right"},  
     {name:'note',index:'note', width:150, sortable:false}  
    ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pcelltbl',
    sortname: 'invdate',
    viewrecords: true,
    sortorder: "desc",
    caption:"Cell Edit Example",
 forceFit : true,
 cellEdit: true,
 cellsubmit: 'clientArray',
 afterEditCell: function (id,name,val,iRow,iCol){
  if(name=='invdate') {
   jQuery("#"+iRow+"_invdate","#list").datepicker({dateFormat:"yy-mm-dd"});
  }
 },
 afterSaveCell : function(rowid,name,val,iRow,iCol) {
  if(name == 'amount') {
   var taxval = jQuery("#list").jqGrid('getCell',rowid,iCol+1);
   jQuery("#list").jqGrid('setRowData',rowid,{total:parseFloat(val)+parseFloat(taxval)});
  }
  if(name == 'tax') {
   var amtval = jQuery("#list").jqGrid('getCell',rowid,iCol-1);
   jQuery("#list").jqGrid('setRowData',rowid,{total:parseFloat(val)+parseFloat(amtval)});
  }
 }
});
jQuery("#list").jqGrid('navGrid','#pgwidth',{edit:false,add:false,del:false});
});
</script>
 
</head>
<body>

<div id="topcontent">
 <br><br>
</div><!-- end topcontainer -->

<div id="centercontent">

<table id="list"><tr><td/></tr></table>
<div id="pager"></div>

<script src="celledit.js" type="text/javascript"> </script>

</div>

<div id="footercontent">
</div><!-- end footercontent -->

</body>
</html>

 
09/01/2012
14:36
Avatar
BioFox
Member
Members
Forum Posts: 4
Member Since:
09/01/2012
sp_UserOfflineSmall Offline

Take a second look at your SQL query, the error says it all.
You are not allowed to have a LIMIT with a negative number, which is your case.
You start with LIMIT -10, 10, instead of LIMIT 0,10.

15/01/2012
04:45
Avatar
cheech74
Member
Members
Forum Posts: 10
Member Since:
31/12/2011
sp_UserOfflineSmall Offline

right thanks - I'm slowly getting there.

However I cant get the data to save to the database - I know its probably something really simple, but coding is not really my thing - just trying to help out a friend. Here is my latest html. I seem to be going round in cicrcles when i google...

many thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Oneline Surveys Weekend Call-Out Rota</title>
<link rel="stylesheet" type="text/css" href="timesheet_login.css">
<link rel="stylesheet" media="print" href="print.css" type="text/css">
<link rel="shortcut icon" href="oneline_logo.gif">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="scripts/js/jqModal.js" type="text/javascript"></script>
<script src="scripts/js/jqDnR.js" type="text/javascript"></script>

<script type="text/javascript">
$(function(){
  $("#rota").jqGrid({
    url:'example.php',
    datatype: "json",
 mtype: 'POST',
    colNames:['Date', 'HPJ', 'Recycler','CCTV','Assistant'],
    colModel:[
     {name:'date',index:'date', width:90,editable:true},
     {name:'hpj',index:'hpj', width:100,editable:true},
      {name:'recycler',index:'recycler', width:100,editable:true},
      {name:'cctv',index:'cctv', width:100,editable:true},
   {name:'assistant',index:'assistant', width:100,editable:true}
    ],
 rowNum:10,
    rowList:[10,20,30],
    pager: '#pcelltbl',
    sortname: 'date',
    viewrecords: true,
    sortorder: "desc",
    caption:"Cell Edit Example",
 forceFit : true,
 cellEdit: true,
 cellsubmit: 'clientArray',
 editurl:'example.php?action=save'
});

jQuery("#rota").jqGrid('navGrid','#pgwidth',{edit:false,add:false,del:false});
});
</script>

 
</head>
<body>

<div id="topcontent">
 <br><br>
</div><!-- end topcontainer -->

<div id="centercontent">

<table id="rota"><tr><td/></tr></table>
<div id="pager"></div>

<script src="celledit.js" type="text/javascript"> </script>

</div>

<div id="footercontent">
</div><!-- end footercontent -->

</body>
</html>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 496

Currently Online:
30 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information