This is what i need to do:
1: Create an empty XML document
2: connect to the database
3: retrieve all blog entries from database
4: create an entry node for each record set, and add the entry node as a child of entries
5: return the XML document as a web page
Below is what i have so far.
[code]
<?php
//filename
$filename = “../xml/blog-dbxml.xml”;
//create empty XML document
$rawBlog = “<?xml version=”1.0″ encoding=”utf-8″ ?>”;
$rawBlog .= “<blog><title>YouCube – The Blog for Cube Puzzlers</title>”;
$rawBlog .= “<author>Puzzler Ruby</author><entries></entries></blog>”;
//Compile xml document header texts
$xml = new SimpleXmlElement($rawBlog);
//database varibale
$dbhost = ‘xxx’;
$username = ‘xxx’;
$password = ‘xxx’;
$dbname = ‘xxxx’;
$port = ‘xxxx’;
//connect to mysql and database
$dbc = mysqli_connect($dbhost, $username, $password, $dbname, $port)
or die(‘Error Connecting to Database: ‘ . mysql_error());
//select database into variable
$query = “select * from Blog;”;
$result = mysqli_query($dbc, $query)
or die(“Could not complete database query at line 26”. mysql_error());
//max number of records
$num = mysqli_num_rows($result);
I am having trouble with the actual array part now, how do i get the values of the array and send them to a xml document?
Here is code form another ‘add to xml document’ i had.
[code]
/* Add the new blog entry as a child node
$entry = $xml->entries->addChild(“entry”);
$entry->addChild(“date”, $_REQUEST[“date”]);
$entry->addChild(“body”, stripslashes($_REQUEST[“body”]));
if ($_REQUEST[“image”] != “”)
$entry->addChild(“image”, $_REQUEST[“image”]);
// Write the entire blog to the file
$file = fopen($filename, ‘w’);
fwrite($file, $xml->asXML());
fclose($file);
?>
*/