Cache-man
Wannabe Webmaster
- Joined
- Mar 16, 2005
- Messages
- 840
- Reaction score
- 0
OK, I've sussed how to connect to the MySQL database using PHP, and have done some queries in order to pull some products from a shop, which is half of my current project sussed
Now from this stage I'd like to be able to output this generated information into a XML file. Does anyone know how/if this is possible? If so, could you give me some pointers.
The code I've done so far to pull the products list and output it to the browser is as follows
Which generates the results shown here http://bigbluesheep.com/xcart/test.php
Now how do I export that to a XML file instead of the browser.
The XML schema will look something like this
Now from this stage I'd like to be able to output this generated information into a XML file. Does anyone know how/if this is possible? If so, could you give me some pointers.
The code I've done so far to pull the products list and output it to the browser is as follows
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Products</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost','bigblues_test','***');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the products database
if (!@mysql_select_db('bigblues_store')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
?>
<h1>MySQL & PHP Integration Test</h1>
<h2>Here are all the products in our database:</h2>
<blockquote>
<?php
// Request the name of all the products
$result = @mysql_query('SELECT product, descr, fulldescr, list_price, MID(image_path, 2) AS image_path FROM xcart_products p INNER JOIN xcart_images_T i ON p.productid = i.id');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each product in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<h3><u>' . $row['product'] . '</u></h3>';
echo '<p>' . $row['descr'] . '<br />';
echo $row['fulldescr'] . '<br />';
echo '<img src="http://www.bigbluesheep.com/xcart' . $row['image_path'] . '" /><br />';
echo '<strong>£' . $row['list_price'] . '</strong></p>';
echo '<hr />';
}
?>
</blockquote>
</body>
</html>
Now how do I export that to a XML file instead of the browser.
The XML schema will look something like this
PHP:
<allitems>
<item>
<name></name>
<description></description>
<description2></description2>
<price></price>
<image></image>
</item>
</allitems>
Last edited: