好的,我正在使用这个foreach
循环来解析xml
以将结果数据添加到我的数据库中,我需要设置该$win
值,但它总是返回 3,当它不应该 b..
$myinfo = simplexml_load_file('http://mysite/results.xml');
foreach ($myinfo->Event as $info):
$cid=$info['EventID'];
$a=$info->Match['AScoreNT'];
$b=$info->Match['BScoreNT'];
if($a > $b){
$win =1;
} elseif($a < $b){
$win =2;
} else{
$win =3;
}
$sql = "
INSERT IGNORE INTO `engine4_event_wins`
SET `win_result` = $win,
`comp_id` = $cid;
";
mysql_query($sql);
endforeach;
<MyFeed>
<Event Sport="AFL" Description="AFL - Finals - Week 1" EventID="651239" FinalDate="2012-09-07T00:00:00">
<Match TeamA="Hawthorn" TeamB="Collingwood" AScoreNT="135" BScoreNT="97"/>
</Event>
<Event Sport="AFL" Description="AFL - Finals - Week 1" EventID="651240" FinalDate="2012-09-08T00:00:00">
<Match TeamA="Adelaide Crows" TeamB="Sydney Swans" AScoreNT="42" BScoreNT="71"/>
</Event>
</MyFeed>