【发布时间】:2013-02-01 16:36:50
【问题描述】:
我正在通过 xml 提要提取有关体育赛事的数据,我正在使用 simplexml 来执行此操作。到目前为止,我得到了一个 foreach 循环,该循环遍历所有事件并将它们作为包含在 <a> 标签中的事件名称列表回显,指向页面 event.php?=id (id 由名为 id 的 events 属性确定)。
使用
<?php
$xml = simplexml_load_file("openbet_cdn.xml");
foreach($xml->response->williamhill->class->type->market as $market) {
$market_attributes = $market->attributes();
printf("<a href=\"event.php?id=%s\">%s</a>\n",
$market_attributes->id,
$market_attributes->name);
}
?>
我遇到的问题是在我的页面 event.php 上,我不断收到显示的 xml 提要中的第一个事件。要做到这一点,我正在使用:
<?php
foreach ($xml->response->williamhill->class->type->market->participant as $participant) {
$participant_attributes = $participant->attributes();
echo "<tr>";
// EVENT NAME
echo "<td>";
echo "<a href=".$market_attributes['url'].">";
echo $participant_attributes['name'];//participants name
echo "</a>";
echo"</td>";
//ODDS
echo "<td>";
echo $participant_attributes['odds'];
echo "</td>";
echo "</tr>";
}
?>
我明白为什么会这样,因为我没有引用活动页面 URL 中的 id。但我不太确定如何做到这一点,知道如何解决这个问题吗?
【问题讨论】: