我有一个脚本可以从表中获取数据并导出到 xml,但我需要从 2 个不同的表中获取数据。
Table 1: Products
i have inside:
id code
Table 2: Stock
i have inside
id qty
我的脚本是:
<?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;
?>
需要帮助根据 Products 表上的 id 从 Stock 结果中获取数量。
欢迎任何帮助。