Jump to content

Recommended Posts

Hello,

 

I have a PHP file that will show some products from Mysql database. this works without any issue.

But I need to create an XML file from this PHP file in order to be able to load it into flash.

I have done the most part and the PHP file creates an XML file on the server and pulls the data (only text format data, i.e. product name, price, details, date added etc etc) and it works perfectly fine BUT, i don't know what to do for the images part!!

This is the original PHP file:

 

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database 
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td>
<td width="83%" valign="top">' . $product_name . '<br />
. $price . '<br />
<a href="product.php?id=' . $id . '">View Product Details</a></td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
 

and this is the PHP file that creates the XML file:

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "../config/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $image = $row["<a href='../product.php?id=" . $id . "'><img src='../inventory_images/" . $id . ".jpg' alt='" . $product_name . "'/></a>"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
    $xmlBody .= '
<Data>
    <DataID>' . $id . '</DataID>
    <DataTitle>' . $product_name . '</DataTitle>
    <DataDate>' . $price . '</DataDate>
    <DataImage>' . $image . '</DataImage>
    <DataDescr>' . $date_added . '</DataDescr>
</Data>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
}
?>
<?php echo $dynamicList; ?>

 

by running the code above, I am keep getting this error:

 

XML Parsing Error: junk after document element
Location: test.php
Line Number 2, Column 1:

<b>Notice</b>:  Undefined index: <a href='../product.php?id=127'><img src='../inventory_images/127.jpg' alt='Example 1'/></a> in <b>test.php</b> on line <b>21</b><br />
^

 

Could someone please help! I am lost!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.