Nandini Posted December 23, 2008 Share Posted December 23, 2008 Hi I want create XML file from mysql table. I have written some script to do that. By using that script xml file was displaying. But database values are not displaying. Here is my script. Can any one tell me where is wrong. <? $host="localhost"; $dbname="test"; $dbtable="white_list"; $dbuser="root"; $dbpass=""; header("content-type:text/xml"); function getXML($sql="Default Query") { $conn=mysql_connect($host,$dbuser,$dbpass); $db=mysql_select_db($dbname); $result = mysql_query($sql,$conn); $columns=""; echo "<records>"; while($row=mysql_fetch_assoc($result)) { $columns.="<record>"; foreach($row as $key => $value) { $columns.="<$key>$value</$key>"; } $columns.="</record>"; } echo $columns; echo "</records>"; } getXML("SELECT * FROM white_list"); ?> Link to comment https://forums.phpfreaks.com/topic/138198-generate-xml-file-from-mysql/ Share on other sites More sharing options...
Mikedean Posted December 23, 2008 Share Posted December 23, 2008 I'm not sure if this will work, but worth a go. Try changing your foreach loop with the following. for ($i = 0; $i < mysql_num_fields($result); $i++) { $fieldName = mysql_field_name($result, $i); $columns.="<" . $fieldName . ">" . $row[$fieldName] . "</" . $fieldName . ">"; } Link to comment https://forums.phpfreaks.com/topic/138198-generate-xml-file-from-mysql/#findComment-722496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.