我有一個XML文件,我想用PHP讀取數據。我已經從中讀取數據,但問題是,我只是想爲一類運行循環,並顯示所有匹配此類別中 這裏是我的XML File link和我的PHP代碼僅循環一個類別XML-PHP
<?php
$test = simplexml_load_file('http://www.goalserve.com/samples/soccer_livescore.xml');
//echo $test->category->matches->match->localteam["name"]."<br>";
//echo $test->category->matches["date"];
?>
<table border="1">
<tr>
<td style="border:none;">Local Team </td>
<td>Score </td>
<td>Visitor team</td>
<td>Status </td>
<td>Date </td>
<td>Time </td>
<td>HT </td>
<td class="hidden-result">Events</td>
</tr>
<?php
foreach ($test->category as $cate) {
foreach ($cate->children() as $matches) {
foreach ($matches->children() as $match) {
// print_r($match);
echo "<td>".$match->localteam["name"]."</td>";
echo '<td><a href="javascript:MoreInformation('.$match["fix_id"].');"><img src="http://www.goalserve.com/images/arrow-down.gif" alt="More information" title="More information" id=I'.$match["fix_id"].'" name=I'.$match["fix_id"].' />'.$match->localteam["goals"].'-'.$match->visitorteam["goals"].'</a></td>';
echo "<td>".$match->visitorteam["name"]."</td>";
echo "<td>".$match["status"]."</td>";
echo "<td>".$match["date"]."</td>";
echo "<td>".$match["time"]."</td>";
echo "<td>".$match->ht["score"]."</td>";
?>
<div class="hidden-result">
<?php
foreach ($match->events->event as $t_event) {
if($t_event["type"]=="goal") {
?>
<td class="hidden-result" id="<?php echo "R".$match["fix_id"]?>" name="<?php echo "R".$match["fix_id"]?>"><img src='images/1.gif' alt=""><?php echo $t_event["player"]."(".$t_event["team"].")" ?></td>
<?php
}
if($t_event["type"]=="yellowcard") {?>
<td class="hidden-result" id="<?php echo "R".$match["fix_id"]?>" name="<?php echo "R".$match["fix_id"]?>"><img src='images/3.gif' alt=""><?php echo $t_event["player"]."(".$t_event["team"].")" ?></td>
<?php
}
if($t_event["type"]=="redcard") {?>
<td class="hidden-result" id="<?php echo "R".$match["fix_id"]?>" name="<?php echo "R".$match["fix_id"]?>"><img src='images/2.gif' alt=""><?php echo $t_event["player"]."(".$t_event["team"].")" ?></td>
<?php
}
}?>
</div>
<?php
echo "</tr>";
}
}
}
?>
</table>
嗨,請更新你的問題並顯示你的XML的有效片段.. – michi