DB to XML (loop Problem)
Posted: Sun Aug 19, 2007 11:51 pm
I am using the following code to convert data in db and display as xml
It displays the subject of only the first row of the database rather than displaying the subjects from all the existing rows. (currently i have around 5 rows in table phpnews_news) It displays only the content of the first row.
I guess there's some problem with the loop.
Code: Select all
<?php
$hostname_conn = "localhost";
$database_conn = "mysql";
$username_conn = "root";
$password_conn = "";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_conn, $conn);
$query_rsAll = "SELECT `subject` FROM `phpnews_news";
$rsAll = mysql_query($query_rsAll, $conn) or die(mysql_error());
$row_rsAll = mysql_fetch_assoc($rsAll);
$totalRows_rsAll = mysql_num_rows($rsAll);
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
echo '<?xml version="1.0" encoding="utf-8"?><root>' ;
if ($totalRows_rsAll > 0) {
echo '<row>';
foreach ($row_rsAll as $column=>$value) {
echo "<$column><![CDATA[" . $row_rsAll[$column] . "]]></$column>";
// note the period . will join strings together.
}
echo "</row>";
}
while ($row_rsAll = mysql_fetch_assoc($rsAll));
echo '</root>';
mysql_free_result($rsAll);
?>I guess there's some problem with the loop.