Forum


14:31

10/11/2009

I wonder if anyone has run into this. I'm trying to create the xml data from mysql using php. When I do this I get no records displaying. however when I run my php file on its own, if i do a view source and copy the output to a file called static.xml and use that file instead all the data works fine. so it makes me think the output from php is fine. but just changing the filename from static.xml to data.php. Makes the data go away. any suggestions?
I think it must be something witht he header but I can't figure it out. I tried taking out the if statement and just using
header ("content-type: text/xml");
but I get the same result
<?php
$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
require “db.php”;
$result = mysql_query(”SELECT COUNT(*) AS count FROM Cert_Itm”);
$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 CertRefNo, CertItemNo, ClientId, ItemDesc FROM Cert_Itm 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'?$et\\n”;
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[CertRefNo].”'>”;
echo “<cell>”. $row[CertRefNo].”</cell>”;
echo “<cell>”. $row[CertItemNo].”</cell>”;
echo “<cell>”. $row[ClientId].”</cell>”;
echo “<cell>”. $row[ItemDesc].”</cell>”;
echo “</row>”;
}
echo “</rows>”;
?>
12:42

10/11/2009

I'm still fighting with this. I am using php 5.1.4 thats why I'm stuck using the XML data format instead of trying to see if I can get json to work instead.
Again the output of my php file is valid xml. if I copy and paste the output into a static file with an .xml extension the grid displays perfectly. Also I do believe now that the header information is correct.
Any suggestions?
11:48

09/11/2009

I don't use XML anymore (JSON is soooo much easier) but I would try to build the whole XML output into a variable and then output that all at once.
[code]
$myvar = “<?xml version='1.0' encoding='utf-8'?>”;
$myvar.="<rows>";
etc....
[/code]
Here is an example of some of my old code:
[code]
[/code]
HTH
17:01

10/11/2009

thanks eljaywilson for your reply,
I tried what you suggested but I'm getting the same results. Valid xml when I look at the file directly but nothing shows up in the grid. I think it must be reading my page as the source php instead of as the output. It's the only thing that makes sense to me. I tried using the full path to the file as well but that did not help either.
Most Users Ever Online: 715
Currently Online:
45 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