Hello,
I'm attempting to generate an xml file through php which pulls from two seperate tables in a single database. I will be the first to admit that I am still learning and it is probably a very simple solution but for some reason i can't seem to figure it out. So any help would be very kind. Here is the code for my recent attempt.
// connection to the database
$dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS)
or die("Unable to connect to MySQL");
// select a database to work with
$selected = mysql_select_db(DB_NAME, $dbhandle)
or die("Could not select examples");
$output = "<?xml version=\"1.0\" ?>\n";
$output .= "<batch>";
$output .="<order>";
// iterate over each table and return the fields for each table
$result_fld = mysql_query( "SELECT orders_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country FROM zen_orders WHERE orders_id >'1'" );
$result_fld2 = mysql_query( "SELECT orders_id, products_model, products_quantity FROM zen_orders_products WHERE orders_id >'1'" );
while( $row1 = mysql_fetch_row($result_fld) ) {
$output .="<ShipTo>";
$output .="<Address>";
$output .="<Po>\"$row1[0]\"</Po>";
$output .= "<Line1>\"$row1[1]\"</Line1>";
$output .= "<Street1>\"$row1[3]\"</Street1>";
$output .= "<Street2>\"$row1[4]\"</Street2>";
$output .= "<City>\"$row1[5]\"</City>";
$output .= "<State>\"$row1[7]\"</State>";
$output .= "<Zip>\"$row1[6]\"</Zip>";
$output .= "<Country>\"$row1[8]\"</Country>";
$output .= "<Country>\"$row1[0]\"</Country>";
$output .= "<Country>\"$test[0]\"</Country>";
$output .="</Address>";
$output .="</ShipTo>";
while($test = mysql_fetch_row($result_fld2)){
if($test[0] == $row1[0] ) {
$output .="<Line>";
$output .= "<model>\"$test[1]\"</model>";
$output .= "<q>\"$test[2]\"</q>";
$output .="</Line>";
}
}
$output .="</order>";
$output .= "</batch>";
// tell the browser what kind of file is come in
header("Content-type: text/xml");
// print out XML that describes the schema
echo $output;
// close the connection
mysql_close($dbhandle);
?>
Thanks again for your help