我有这个脚本可以读取解析的 xml(外部):
<?php
//mysql connection
$con2 = mysql_connect("localhost","username","password");
if (!$con2)
{
die('Could not connect: ' . mysql_error());
}
$selectdb = mysql_select_db("test_db", $con2);
if (!$selectdb)
{
die('Database not used: ; ' . mysql_error());
}
//simplexml load xml file
$jackpots = simplexml_load_file('https://www.123.com/xmldata.xml');
//loop through parsed xmlfeed and print output
foreach ($jackpots->jackpot as $jackpot) {
foreach ($jackpots->jackpot as $jackpot) {
printf("gameId: %s\n", $jackpot->gameId);
printf("gameName: %s\n", $jackpot->gameName);
printf("amount: %s\n", $jackpot->amount);
printf("currency: %s\n", $jackpot->currency);
//insert into databse
foreach ($jackpots->gameId as $jackpot) {
mysql_query("UPDATE my_table SET amount=$jackpot->amount")
or die(mysql_error());}
//show updated records
printf ("Records inserted: %d\n", mysql_affected_rows());
}
}
//close connection
mysql_close($con2);
?>
显然,我在数据库中有一个表(my_table),其中包含所有列(gameId、gameName、金额和货币)。
我需要为每个“gameId”列更新“金额”列。当我运行下面的脚本时,我得到了更新,但所有的“金额”都是一样的。请给我一些支持好吗?我的错误在哪里?
提前致谢!