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
php mysql data
11/11/2009
14:31
Avatar
Dmoney
Member
Members
Forum Posts: 8
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

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/11/2009
10:42
Avatar
Dmoney
Member
Members
Forum Posts: 8
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

still can't get dynamic xml to work.  copying and pasting the output into a static file works fine though.

13/11/2009
12:42
Avatar
Dmoney
Member
Members
Forum Posts: 8
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

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?

16/11/2009
11:48
Avatar
eljaywilson
Member
Members
Forum Posts: 22
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

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]

$return_value = '<?xml version="1.0"?><root>
<storename>'. $storename .'</storename><storeaddress>'.$storeaddress.'</storeaddress>
<storecity>'.$storecity.'</storecity><storestate>'.$storestate.'</storestate>
<storezip>'.$storezip.'</storezip><storephone>'.$storephone.'</storephone>
<storetax>'.$storetax.'</storetax><storeid>'.$storeid.'</storeid>
<registernum>'.$registernum.'</registernum>
<checkreader>'.$checkreader.'</checkreader>
<workspace1>'.$workspace1.'</workspace1>
<workspace2>'.$workspace2.'</workspace2>
<workspace3>'.$workspace3.'</workspace3>
<pole>'.$pole.'</pole>
<cc_processing>'.$cc_processing.'</cc_processing>
<auto_logout>'.$auto_logout.'</auto_logout>
<mgr_check_cashing>'.$mgr_check_cashing.'</mgr_check_cashing>
<chg_acct_posting>'.$chg_acct_posting.'</chg_acct_posting>
<cc_test_mode>'.$cc_test_mode.'</cc_test_mode>
<ipaddress>' .$remoteip . '</ipaddress>';
$sql ="select departmentname AS DEPTNAME, taxable AS DEPTTAX from tblDepartments ORDER BY departmentid ASC" ;
$rs = $db->query($sql);
while ($row = $db->fetch_array($rs))
{
$return_value.= '<dept>
<deptname>' . $row['DEPTNAME'] . '</deptname>
<depttax>' . $row['DEPTTAX'] . '</depttax>
</dept>';
}
$return_value.='</root>';   
[/code]
Then at the bottom of the page use this to output it:
[/code]
// Add header information so that IE won't cache the response
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");
header("content-type: text/xml");
echo $return_value; // This will become the response value for the XMLHttpRequest object

[/code]

HTH

16/11/2009
17:01
Avatar
Dmoney
Member
Members
Forum Posts: 8
Member Since:
10/11/2009
sp_UserOfflineSmall Offline

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.

16/11/2009
17:11
Avatar
eljaywilson
Member
Members
Forum Posts: 22
Member Since:
09/11/2009
sp_UserOfflineSmall Offline

Send me script files and let me play with it.  Leave out database connection info, instead just give me table layout info and I will just create a table on my DB and stick some dummy data in it.

Can zip it all up and send to:

eljaywilson_at_gmail_dot_com

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information