我试图在php中显示xml文件数据,但由于while循环它重复数据更多然后需要执行
代码......
// display data in table
echo "<table border='3' width='900' height='5' cellpadding='6' class='CSSTableGenerator'>";
echo '<tr>';
echo '<td> '. $lang ['IMAGE'] ; ' </td>';
echo'<td>ID</td>';
echo '<td> '. $lang ['PRODUCT_NAME'] ; ' </td>';
echo '<td> '. $lang ['PRODUCT_CATAGORY'] ; ' </td>';
echo '<td> '. $lang ['PRODUCT_DESCRIPTION'] ; ' </td>';
echo '<td> '. $lang ['PRODUCT_PRICE'] ; ' </td>';
"</tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
$xml = new SimpleXMLElement('<xml/>');
if(! $xml = simplexml_load_file('french_products.xml'));
foreach($xml->children() as $Products){
// echo out the contents of each row into a table
echo "<tr>";
echo '<td><b>' . $row['id'] . '</b></td>';
echo '<td><b>' . $Products->product_name. '</b></td>';
echo '<td><b>' . $row['product_category'] . '</b></td>';
echo '<td><b>' . $row['product_description'] . '</b></td>';
echo '<td><b>' . $row['product_price'] . '</b></td>';
}
}
// close table>
echo "</table>";
?>
答案 0 :(得分:0)
$xml = new SimpleXMLElement('<xml/>');
if(! $xml = simplexml_load_file('french_products.xml'));
在while循环之前编写此代码。希望这可以帮到你。