Forum Moderators: open

Message Too Old, No Replies

xml output from php query

         

j milo taylor

9:56 am on May 19, 2008 (gmt 0)

10+ Year Member



I need to output the contents of a mysql database as xml as a response to a php query. i'm almost there, bu this code doesn't quite work, i think there is some contradiction with the mysql_fetch_assoc and mysql_num_rows instances:

any help would be greatfully received:

<?php require_once('Connections/immapp.php'); ?>

<?php

mysql_select_db($database_immapp, $immapp);
$recordID = $_GET['recordID'];
$query_rs_country = "SELECT * FROM artist WHERE location_id_artist = $recordID ORDER BY 'year_artist'";
$rs_country = mysql_query($query_rs_country, $immapp) or die(mysql_error());
$row_rs_country = mysql_fetch_assoc($rs_country); //--- problem here?
$totalRows_rs_country = mysql_num_rows($rs_country); //-- here?

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<artists>\n";

for($x = 0 ; $x < mysql_num_rows($rs_country) ; $x++){ //--re here?
$row = mysql_fetch_assoc($rs_country); //--- and here?
$xml_output .= "\t<artist>\n";
$xml_output .= "\t\t<Artist_Image>" . $row['imageTB_artist'] . "</Artist_Image>\n";
$xml_output .= "\t\t<Artist_First_Name>" . $row['1stname_artist'] . "</Artist_First_Name>\n";
$xml_output .= "\t\t<Artist_Second_Name>" . $row['2ndname_artist'] . "</Artist_Second>\n";
$xml_output .= "\t\t<Artist_Year>" . $row['year_artist'] . "</Artist_Year>\n";
$xml_output .= "\t\t<Artist_Country>" . $row['country_artist'] . "</Artist_Country>\n";

$xml_output .= "\t</artist>\n <br />";
}

$xml_output .= "</artists>";

$filename = 'XML-ARTIST_COUNTRY.xml';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open ($filename)";
exit;
}
if (fwrite($handle, $xml_output) === FALSE) {
echo "Cannot write to ($filename)";
exit;
}
echo "Success, wrote <br> ($xml_output) to ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>

----
thanks
milo

cmarshall

10:21 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might have better luck asking this question in the PHP forum [webmasterworld.com].

tomda

10:28 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep ! It's a PHP problem... To investigate, print the array

print_r($row_rs_country);

j milo taylor

10:54 am on May 19, 2008 (gmt 0)

10+ Year Member



thanks for the advice. i'll try over there

cheers
milo

encyclo

11:04 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Continues here: [webmasterworld.com...]