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_TopicIcon
GRID DOES NOT SHOW DATA
05/02/2012
04:00
Avatar
emily
New Member
Members
Forum Posts: 2
Member Since:
05/02/2012
sp_UserOfflineSmall Offline

Hello!

I did the basic installation but I dont display any data on the grid!

Here is the example.php code:

<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password
include("connect1.php");
 
// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
$page = $_GET['page'];
 
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];
 
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
 
// sorting order - at first time sortorder
$sord = $_GET['sord'];
 
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;
 

 
// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM users");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
 
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
              $total_pages = ceil($count/$limit);
} else {
              $total_pages = 0;
}
 
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
 
// calculate the starting position of the rows
$start = $limit*$page - $limit;
 
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
 
// the actual query for the grid data
$SQL = "SELECT first_name, last_name, occupation, address,email, telephone_a FROM users,identity_card ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
 
// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml;charset=utf-8");
 
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";
 
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $s .= "<row id='". $row['identity_card']."'>";            
    $s .= "<cell>". $row['identity_card']."</cell>";
    $s .= "<cell>". $row['last_name']."</cell>";
    $s .= "<cell>". $row['occupation']."</cell>";
    $s .= "<cell>". $row['address']."</cell>";
    $s .= "<cell>". $row['email']."</cell>";
    $s .= "<cell>". $row['first_name']."</cell>";
    $s .= "<cell><![CDATA[". $row['telephone_a']."]]></cell>";
    $s .= "</row>";
}
$s .= "</rows>";
 
echo $s;
?>

And here is the myfirstgrid.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>My First Grid</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.8.17.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<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="js/jqDnR.js" type="text/javascript"></script>

<script src="js/jqModal.js" type="text/javascript"></script>
 
 <style>
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>

<script type="text/javascript">
$(function(){
  $("#list").jqGrid({
    url:'example.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['ΤαυτÏŒτητα','ÎŒνομα','Επίθετο', 'ΑπασχÏŒληση','Διεύθυνση','Εmail','Tηλέφωνο'],
    colModel :[
      {name:'identity_card', index:'identity_card', width:55},
      {name:'first_name', index:'first_name', width:55},
      {name:'last_name', index:'last_name', width:90},
      {name:'occupation', index:'occupation', width:80, align:'right'},
      {name:'address', index:'address', width:80, align:'right'},
      {name:'email', index:'email', width:80, align:'right'},
      {name:'telephone_a', index:'telephone_a', width:150, sortable:false}
    ],
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'identity_card',
    sortorder: 'desc',
    viewrecords: true,
    gridview: true,
    caption: 'My first grid'
  });
});
</script>

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

Does anyone see any mistakes?

I followed the instructions from this link for my first grid:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid

05/02/2012
18:33
Avatar
chrismark
Member
Members
Forum Posts: 11
Member Since:
08/10/2011
sp_UserOfflineSmall Offline

Check the xml that example.php outputs.

header("Content-type: text/xml;charset=utf-8″); <-- last double quote here doesn't look right.

05/02/2012
18:41
Avatar
emily
New Member
Members
Forum Posts: 2
Member Since:
05/02/2012
sp_UserOfflineSmall Offline

How I will check the xml that example.php outputs?

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
48 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