私はまだphpでxmlデータを処理する方法を学んでいますが、
これは、 xml 要素の値に応じた、以前の質問フロー制御の 2 番目の部分です。
「PRICE」タグに応じてアイテムを降順または昇順で表示できるようにする必要があります。
これまでのコードは次のとおりです。
<?php
$itm = $_GET['itm'];
$ITEMSS = new SimpleXMLElement('items.xml', null, true);
echo <<<EOF
<table width="100%" align="center" border="1" bordercolor="#0099ff" cellpadding="1" cellspacing="0">
<tr>
<th bgcolor="#66ccff"><span class="style4">ITEM Name</span></th>
<th bgcolor="#66ccff"><span class="style4">item TYPE </span></th>
<th bgcolor="#66ccff"><span class="style4">item DESCIPTION </span></th>
<th bgcolor="#66ccff"><span class="style4">item PRICE</span></th>
</tr>
EOF;
foreach($ITEMSS as $ITEMS) // loop through our DATAS
{
if($ITEMS->TITLE=="$itm")
{
echo <<<EOF
<tr height="30" align=middle>
<td>{$ITEMS->TITLE}</td>
<td>{$ITEMS->TYPE}</td>
<td>{$ITEMS->DESCIPTION}</td>
<td>{$ITEMS->PRICE}</td>
</tr>
EOF;
}
}
echo '</table>';
?>
xml ツリーは次のとおりです: http://fast-ptp.fr.cr/xml/items.xml
これが私がテストしているページです: