Forum



22:38

25/01/2012

EDIT 3: Ok the problem was I was using the standard document that dreamweaver creates so I removed all the HTML tags and now if I do http://findajob.zapto.org/fb/g.....8;sord=ASC
It actually outputs the correct xml ie:
EDIT 2: If I manually pass params to my php script I get:
This page contains the following errors:error on line 10 at column 6: XML declaration allowed only at the start of the documentBelow is a rendering of the page up to the first error.
Which is <?php
Hello,
I'm new to jqgrid, jquery and PHP althought I do have a decent amount of development experience, I have the following code and it simply returns a blank grid(I dont get a record <num> out of <num> at the bottom right and the NAV bit doesnt appear. sorry for the long code listing but I've noticed people generally dont include enough info so i'm going all in….
This is cut and pasted right out of the WIKI along with the data and the db structure so I cant figure out why its not working.
EDIT: I even got the griddata to output the xml to a textfile and it looks right to me.
Main page is below, griddata.php is at the bottom…
INDEX.PHP
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>Facebook – FindaJob Test App</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery.colorbox-min.js"></script>
<link type="text/css" href="jqueryui/css/smoothness/jquery-ui-1.8.17.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="jqueryui/js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="menu/menu.js"></script>
<link type="text/css" href="menu/menu.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="colorbox.css" />
<link rel="stylesheet" type="text/css" media="screen" href="jqgrid/css/ui.jqgrid.css" />
<script src="jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).bind('cbox_closed', function() {
window.location.href = 'newuser.php';
});
</script>
<?php
require 'facebook/src/facebook.php';
require_once 'auth.php';
include 'sqlfuncs.php';
include 'testgrid.php';
include 'userfuncs.php';
//session_start();
//3. requesting 'me' to API
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$newuser = uidisnew($uid);
$_SESSION['fb_session_key'] = $session['session_key']; // store session key
} catch (FacebookApiException $e) {
error_log($e);
}
}
//4. login or logout
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
if($newuser==0){
}
else
{
?>
<script type="text/javascript">
$(document).ready(function(){
$.colorbox({href:"login.html"});
});
</script>
<?php
}
?>
</head>
<body>
<div id="menucont">
<div id="menu">
<ul class="menu">
<li><a href="#"><span>Logout</span></a></li>
<li><a href="#"><span>Help</span></a></li>
<li class="last"><a href="#"><span>Settings</span></a></li>
<li><a href="#"><span>Search</span></a>
</li>
<li><a href="#" class="parent"><span>Home</span></a>
<div>
<ul>
<li><a href="#"><span>Sub Item 1</span></a></li>
<li><a href="#"><span>Sub Item 2</span></a></li>
<li><a href="#"><span>Sub Item 3</span></a></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<table id="list1″><tr ><td /></tr ></table >
<div id="pager1″></div >
</body>
</html>
<a href="http://apycom.com/"</a>
<script type="text/javascript">
$(document).ready(function(){
jQuery("#list1″).jqGrid({
url:'griddata.php?q=1',
datatype: "xml",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:75},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name', width:100},
{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}
],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"XML Example"
}).navGrid('#pager1',{edit:false,add:false,del:false});
});
</script>
This is the griddata.php that should return the XML(griddata.php)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password
ini_set("display_errors",1);
$dbuser='SOMEUSER';
$dbpassword='SOMEPASS';
$dbhost="localhost";
$database='SOMEDB';
// 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;
// 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.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
$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());
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>";
echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "<row id='". $row[id]."'>";
echo "<cell>". $row[id]."</cell>";
echo "<cell>". $row[invdate]."</cell>";
echo "<cell><![CDATA[". $row[name]."]]></cell>";
echo "<cell>". $row[amount]."</cell>";
echo "<cell>". $row[tax]."</cell>";
echo "<cell>". $row[total]."</cell>";
echo "<cell><![CDATA[". $row[note]."]]></cell>";
echo "</row>";
}
echo "</rows>";
?>
</body>
</html>
00:21

25/01/2012

Hi guys,
Right i've figured it all out now, heres the howto for newbies like me when following the wiki tutorial for Mysql and xml datasource.
1) Make sure if your using dreamweaver you dont keep any of the content that DW creates for you when you make a new file, remove all the existing HTML tags so all you have is the stuff between '<?php' and '?>'.
2) there is a typo in the wiki, sortname: 'id', SHOULD BE sortname: 'invid', when setting up the grid(the bit where you do jQuery("#list1").jqGrid({ blah blah
I know these were probably basic mistakes but hopefully it'll help someone.
Cheers
Marc
Most Users Ever Online: 715
Currently Online:
71 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