les paso el codigo del js:
Código:
este es el codigo php: jQuery("#list11").jqGrid({ url:'subgrid.php?q=1', datatype: "xml", height: 200, colNames:['Nro_ticket','Nro_mesa', 'Total'], colModel:[ {name:'nro_ticket',index:'nro_ticket', width:55}, {name:'nro_mesa',index:'nro_mesa', width:90}, {name:'Total',index:'Total', width:100} ], rowNum:10, rowList:[10,20,30], pager: '#pager11', sortname: 'nro_ticket', viewrecords: true, sortorder: "desc", multiselect: false, subGrid : true, subGridUrl: 'subgrid.php?q=2', subGridModel: [{ name : ['Descripcion','Precio'], width : [100,200] } ], caption: "Ticket" }); jQuery("#list11").jqGrid('navGrid','#pager11',{add:false,edit:false,del:false});
Código PHP:
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;
if(!$sord) $sord ="asc";
if(!$limit) $limit =10;
// search options
// IMPORTANT NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// this type of constructing is not recommendet
// it is only for demonstration
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
$fld = Strip($_REQUEST['searchField']);
if( $fld=='num' || $fld =='item' || $fld=='qty' || $fld=='unit' ) {
$fldata = Strip($_REQUEST['searchString']);
$foper = Strip($_REQUEST['searchOper']);
// costruct where
$wh .= " AND ".$fld;
switch ($foper) {
case "bw":
$fldata .= "%";
$wh .= " LIKE '".$fldata."'";
break;
case "eq":
if(is_numeric($fldata)) {
$wh .= " = ".$fldata;
} else {
$wh .= " = '".$fldata."'";
}
break;
case "ne":
if(is_numeric($fldata)) {
$wh .= " <> ".$fldata;
} else {
$wh .= " <> '".$fldata."'";
}
break;
case "lt":
if(is_numeric($fldata)) {
$wh .= " < ".$fldata;
} else {
$wh .= " < '".$fldata."'";
}
break;
case "le":
if(is_numeric($fldata)) {
$wh .= " <= ".$fldata;
} else {
$wh .= " <= '".$fldata."'";
}
break;
case "gt":
if(is_numeric($fldata)) {
$wh .= " > ".$fldata;
} else {
$wh .= " > '".$fldata."'";
}
break;
case "ge":
if(is_numeric($fldata)) {
$wh .= " >= ".$fldata;
} else {
$wh .= " >= '".$fldata."'";
}
break;
case "ew":
$wh .= " LIKE '%".$fldata."'";
break;
case "ew":
$wh .= " LIKE '%".$fldata."%'";
break;
default :
$wh = "";
}
}
}
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error conecting to db.");
switch ($examp) {
case 1:
$result = mysql_query("SELECT COUNT(*) AS count FROM ticket ".$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 T.nro_ticket,T.nro_mesa,SUM(P.precio)+SUM(B.precio) as Total FROM `ticket` as T inner join posee as Pb on T.nro_ticket = Pb.nro_ticket inner join tiene as Tp on T.nro_ticket = Tp.nro_ticket inner join bebida as B on Pb.nro_bebida = B.nro_bebida inner join plato as P on P.nro_plato = Tp.nro_plato where 1=1 ".$wh." group by T.nro_ticket 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]['nro_ticket']=$row['nro_ticket'];
$responce->rows[$i]['cell']=array($row['nro_ticket'],$row['nro_mesa'],$row['Total']);
$i++;
}
//echo $json->encode($responce);
echo json_encode($responce);
break;
case 2:
$id = $_GET['id'];
$SQL = "SELECT B.descripcion as Descripcion,B.precio as Precio FROM `ticket` as T inner join posee as Pb on T.nro_ticket = Pb.nro_ticket inner join tiene as Tp on T.nro_ticket = Tp.nro_ticket inner join bebida as B on Pb.nro_bebida = B.nro_bebida inner join plato as P on P.nro_plato = Tp.nro_plato where T.nro_Ticket = ".$id."group by T.nro_ticket
union
SELECT P.descripcion as Descripcion,P.precio as Precio FROM `ticket` as T inner join posee as Pb on T.nro_ticket = Pb.nro_ticket inner join tiene as Tp on T.nro_ticket = Tp.nro_ticket inner join bebida as B on Pb.nro_bebida = B.nro_bebida inner join plato as P on P.nro_plato = Tp.nro_plato where T.nro_ticket = ".$id." group by T.nro_ticket ORDER BY nro_ticket";
$result = mysql_query( $SQL ) or die("Couldn?t execute query.".mysql_error());
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";
echo "<?xml version='1.0' encoding='utf-8'?$etn";
echo "<rows>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "<row>";
echo "<cell>". $row['Descripcion']."</cell>";
echo "<cell><![CDATA[". $row['precio']."]]></cell>";
echo "</row>";
}
break;
}
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;
}
el error es el siguiente:
Código:
el problema es que la variable tiene contendido asi que no tengo ni idea porque me tira ese error. Y el segundo problema es que no me muestra nada en la grilla...<br /> <b>Warning</b>: Creating default object from empty value in <b>C:\xampp\htdocs\jqgrid\subgrid.php</b> on line <b>116</b><br /> {"page":"1","total":1,"records":"5","rows":[{"nro_ticket":"104","cell":["104","7","709"]},{"nro_ticket":"103","cell":["103","9","124"]},{"nro_ticket":"102","cell":["102","4","122"]},{"nro_ticket":"101","cell":["101","6","110"]},{"nro_ticket":"100","cell":["100","3","457"]}]
Si tienen idea como puedo arreglarlo se los voy a agradescer. Saludos,Mery