I have a script to get data from a table and export to xml, but i need to get the data from 2 different tables.
Table 1: Products
i have inside:
id code
Table 2: Stock
i have inside
id qty
my script is:
<?php
$db_host = "localhost";
$db_name = "test";
$db_username = "root";
$db_password = "";
$dbh = mysql_connect($db_host, $db_username, $db_password) or die("Unable to connect to MySQL");
mysql_query('SET NAMES "utf8"');
mysql_select_db($db_name, $dbh) or die("Could not select $db_name");
$sql = "select * from products ";
$q = mysql_query($sql);
$custom = '"';
$xml = "\n";
$xml .= "<XML>\n";
while($r = mysql_fetch_assoc($q))
{
$xml .= " <PRODUCT code=$custom " . $r["code"] . "$cusmot qty=$custom " . $r["qty"] . "$custom />\n";
}
$xml .= "</XML>";
header("Content-type: text/xml");
echo $xml;
?>
Need help to get the qty from Stock result according the id on Products table.
Any help is welcome.
Try changing your SQL to pull data from both tables:
select p.code, s.qty from products p, stock s where p.id = s.id. With that change it looks like your PHP will almost (or completely) work!