I've had this issue with an XML File i've been trying to echo out using PHP Without making 1 long line of text.
I run this code first to create my XML page, of all the products in my database:
<?php $cfg = Array(); $cfg['db_host'] = '***'; $cfg['db_user'] = '***'; $cfg['db_password'] = '***'; $cfg['db_name'] = '***'; mysql_connect($cfg['db_host'], $cfg['db_user'], $cfg['db_password']); mysql_select_db($cfg['db_name']); unset($cfg); $result = mysql_query("SELECT * FROM Artikelen"); $xml = new SimpleXMLElement('<xml/>'); while($row = mysql_fetch_assoc($result)) { $draw = $xml->addChild('draw'); $draw->addChild('Product_Id',$row['Pr_Id']); $draw->addChild('Product',$row['Product']); $draw->addChild('Prijs',$row['Prijs']); } $fp = fopen("Artikelen.xml","wb"); fwrite($fp,$xml->asXML()); fclose($fp); ?> Then i run this code from another file to show the .XML:
<?php $xml=simplexml_load_file("Artikelen.xml"); print_r($xml); ?> What this shows is:
SimpleXMLElement Object ( [draw] => Array ( [0] => SimpleXMLElement Object ( [Product_Id] => 1 [Product] => Pizza Margherita [Prijs] => 7.00 ))) Times 11 in 1 long line, since i have 11 products. I've tried some things as:
<?php $xml=simplexml_load_file("Artikelen.xml"); echo $xml->Product_Id . "<br>"; echo $xml->Product . "<br>"; echo $xml->Prijs . "<br><br>"; ?> But this doesn't seem to work.
This is my first time working with XML files, so it might be a very simple solution.
Thanks in Advance!, If you seem to miss information please let me know.