Forum



01:15

26/03/2010

( apologize, and publish this post but do not see )
<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>Primera matriz</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/vader/jquery-ui-1.8.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-sp.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'ejemplo.php?q=1',
datatype: 'json',
mtype: 'POST',
colNames:['Inv No','Fecha', 'Monto','Impuesto','Total','Notas'],
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:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
{name:'note', index:'note', width:150, sortable:false}
],
pager: '#pager', /* indica el elemento donde ir la barra de paginacin*/
rowNum:10,
rowList:[5,10,15,20,25,30],
sortname: 'invid',
sortorder: 'desc',
viewrecords: true,
caption: 'Mi primera matriz de datos con JqGrid'
});
jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
});
</script>
</head>
<body>
<table id="list"></table>
<div id="pager"></div>
</body>
</html>
include("dbconfig.php");
// coment the above lines if php 5
//include("JSON.php");
//$json = new Services_JSON();
// end comment
$examp = $_REQUEST["q"]; //query number
$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;
$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
$sarr = Strip($_REQUEST);
foreach( $sarr as $k=>$v) {
switch ($k) {
case 'invid':
case 'invdate':
case 'note':
$wh .= " AND ".$k." LIKE '".$v."%'";
break;
case 'amount':
case 'tax':
case 'total':
$wh .= " AND ".$k." = ".$v;
break;
}
}
}
//echo $wh;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());
mysql_select_db($dbs) or die("Error conecting to db.");
switch ($examp) {
case 1:
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader".$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)
if ($start<0) $start = 0;
$SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Could not 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]['invid']=$row['invid'];
$responce->rows[$i]['cell']=array($row['invid'],$row['invdate'],$row['amount'],$row['tax'],$row['total'],$row['note']);
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
case 3:
}
mysql_close($db);
function Strip($value)
{
if(get_magic_quotes_gpc() != 0)
{
if(is_array($value))
if ( array_is_associative($value) )
{
foreach( $value as $k=>$v)
$tmp_val[$k] = stripslashes($v);
$value = $tmp_val;
}
else
for($j = 0; $j < sizeof($value); $j++)
$value[$j] = stripslashes($value[$j]);
else
$value = stripslashes($value);
}
return $value;
}
function array_is_associative ($array)
{
if ( is_array($array) && ! empty($array) )
{
for ( $iterator = count($array) - 1; $iterator; $iterator-- )
{
if ( ! array_key_exists($iterator, $array) ) { return true; }
}
return ! array_key_exists(0, $array);
}
return false;
}
?>
01:58

04/11/2009

This is a PHP to SQL issue, not a jqGrid issue.
From what I can see, not understanding anything about PHP, your
case 'invid':
is not being applied to the varialbe $wh
To troubleshoot this put your debugger on and look at the output for $wh inside your
switch ($examp) {
case 1:
statement.
or just look at the actual SQL being sent to the database.
tim
02:32

26/03/2010

Hi Tim.
It was certainly a problem in PHP to SQL.
I mistakenly thought Jqgrid did everything. And of course, PHP and MYSQL code must be written by each user. Mainly MYSQL code for search functions.
The search module works for me as it is, but it was a difficult task to achieve.
For anyone who has the same doubt, the lesson learned is that: the code to execute searches with Jqgrid must be written yourself. The demos are just that, demos!
Thanks again Tim.
Most Users Ever Online: 715
Currently Online:
52 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