Forum
16:23
06/06/2014
i m debuting with jqgrid and i found it intersting so i started working with it but it was not a good strat i v got always an empty grid
this is a code html index.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" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My First Grid</title><link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.10.4.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.11.0.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 type="text/javascript">
$(function () {
jQuery("#list").jqGrid({
url:'server.php?q=2',
datatype: "json",
colNames:['id_dossier','cin', 'codecin', 'nom_prenom','date_naiss','lieu_naiss','sexe'],
colModel:[
{name:'id_dossier',index:'id_dossier', width:55},
{name:'cin',index:'cin', width:90},
{name:'codecin',index:'codecin', width:100},
{name:'nom_prenom',index:'nom_prenom', width:80, align:"right"},
{name:'date_naiss',index:'date_naiss', width:80, align:"right"},
{name:'lieu_naiss',index:'lieu_naiss', width:80,align:"right"},
{name:'sexe',index:'sexe', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager',
sortname: 'id_dossier',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
});
</script></head>
<body>
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>
</body>
</html>
and this the php fileÂ
<?php
//connection au serveur
$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", "rot", "")or die("Connection Error: " . mysql_error());mysql_select_db("recrutement") or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM license a, license b WHERE a.id_dossier=b.id_dossier");
$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 id_dossier, cin, codecin, nom_prenom, date_naiss,lieu_naiss, sexe FROM license 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_dossier']=$row[id_dossier];
$responce->rows[$i]['cell']=array($row[id_dossier],$row[cin],$row[codecin],$row[nom_prenom],$row[date_naiss],$row[lieu_naiss],$row[sexe]);
$i++;
}
header("Content-Type: application/json; charset=utf-8");echo json_encode($responce);
?>
Most Users Ever Online: 715
Currently Online:
61 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