0

I am trying to print a table with the list of customer oder from data retrieved from an xml file. I think my attempt at retrieving data has failed as it did not show anything. I also wanted to add two buttoms at the end of each order (delet and edit):

<?php 
// Loading the XML file
$xml = simplexml_load_file("database/orderlist.xml");

echo "
<div style='overflow-x:auto;'>
<table id='order'>
  <tr>
   
    <th>Order #</th>  
    <th>Customer ID# </th>
    <th>Items</th>
    <th>Total Prices (CND)</th>
    

  </tr>
    foreach($xml->children() as $ftpxml)
    {
        echo '<td>".$ftpxml->attributes()->id."</td>';
        echo '<td> ".$ftpxml->attributes()->customerID." </td>';
        echo '<td>".$ftpxml->attributes()->products." </td>';
        echo '<td>".$ftpxml->attributes()->totalprice." </td>';
        echo '<a href="backStoreOrderProfile.html" ><button class="btn Edit" id="btn" input value="Check" type=submit > Edit </button></a>';
        echo '<button class="btn Delete" id="btn" input value="Check" type=submit > Delete</button></td>';
    }
    </table>
    </div>
    ";
?>

5
  • thank you very much for answering! I fixed it but still some errors showing on the </table> tag tho Commented Aug 16, 2021 at 15:45
  • thanks Ken. still it could not recognize attributes. it printed the codes such as .$ftpxml->attributes()->id. instead Commented Aug 16, 2021 at 16:53
  • change ALL '<td>" to '<td>' and ALL "</td>' to '</td>' please Commented Aug 16, 2021 at 17:15
  • hey Ken sorry to be a bother I still had trouble printing out a table. i am pretty new to this forum i dont know how to add more codes to my original question. but you could find my xml file here:jsfiddle.net/caizhangbin/eqLt8dp1/1 Commented Aug 16, 2021 at 18:11
  • I have read your XML file and amended your code (please see my answer below) Commented Aug 16, 2021 at 19:11

1 Answer 1

1

You have a number of problems in your codes

  1. make sure you end each php statement by a semi-colon
  2. make sure you enclose the string in same quotation marks
  3. make sure you traverse the XML hierarchy properly
<?php
// Loading the XML file
$xml = simplexml_load_file("database/orderlist.xml");
echo "
<div style='overflow-x:auto;'>
<table border=1 cellpadding=5 id='order' style='border-collapse: collapse;' bordercolor='#DDDDDD'>
  <tr>
   
    <th>Order #</th>  
    <th>Customer ID# </th>
    <th>Items</th>
    <th>Total Prices (CND)</th>
    <th>Edit
    <th>Delete
    

</tr>";
foreach ($xml->oder as $ftpxml) {
?>
<tr>
<td><?php echo $ftpxml->id; ?>
<td><?php echo $ftpxml->customerID; ?>
<td>
    <?php
    foreach ($ftpxml->products->product as $ftpxml2) {
        echo $ftpxml2->productName . " ";
    } ?>
<td>
    <?php echo $ftpxml->totalprice; ?>

<?php
    echo '<td><a href="backStoreOrderProfile.html" ><button class="btn Edit" id="btn" input value="Check" type=submit > Edit </button></a>';
    echo '<td><button class="btn Delete" id="btn" input value="Check" type=submit > Delete</button></td>';
?>

<?php
} ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.