0

Hi I got a bit of a problem,

I am retreiving an XML like so:

    // create new document object
    $dom_object = new DOMDocument();
    // load xml file
    $dom_object->load("http://www.mhs2000.de/hpm/v6/machinelist-master.php?hid=1007&lang=de&GroupID=01002");

    $item = $dom_object->getElementsByTagName("product");

        foreach( $item as $value )
    {

    $nos = $value->getElementsByTagName("MachineNo");
    $no  = $nos->item(0)->nodeValue;
    $machineno = str_replace( "1007-", "", $no );

    $herstellers = $value->getElementsByTagName("Make");
    $hersteller  = $herstellers->item(0)->nodeValue;


    $types = $value->getElementsByTagName("Type");
    $type  = $types->item(0)->nodeValue;

    $labels = $value->getElementsByTagName("NewIn");
    $label  = $labels->item(0)->nodeValue;

    $controltypes = $value->getElementsByTagName("ControlType");
    $controltype  = $controltypes->item(0)->nodeValue;


    $bildurls = $value->getElementsByTagName("BildUrl");
    if($bildurls->length == 0)
    {
        $bildurl = ("/wp-content/themes/framework/images/logo.jpg");
    }
    else
    $bildurl  = $bildurls->item(0)->nodeValue;

    $tdetailsformats = $value->getElementsByTagName("tdetailsformat");
    $tdetailsformat  = $tdetailsformats->item(0)->nodeValue;
    $tdetailsformat = str_replace( "|", " ", $tdetailsformat );
    $tdetailsformat = str_replace( "%", "", $tdetailsformat );


    echo "<div class=\"row span_16\">";
    echo "<div class=\"col span_4 clr\">";
    echo "<a href=\"$bildurl\">";
    echo "<img src=\"$bildurl\" class=\"thumb\">";
    echo "</a>";
    echo "</div><div class=\"col span_12 clr\">";
    echo "$machineno $hersteller - $type - $label - $controltype - $tdetailsformat";
    echo "</div>";
    echo "</div>";
    }

So everythings working fine, but What do I have to do to put a Table around the results?

When I open a tag it appears below my results.

<div class="col span_12 clr">6056 HELLER - BEA 05 - 1986 - CNC - x-Weg 500 mm y-Weg 400 mm z-Weg 560 mm Spindeldurchmesser 70 mm Aufnahme SK 40 </div>
<table></table>

Thanks in advance.

1
  • You need to format the echo statements and use table tag properly. Commented Oct 29, 2012 at 7:13

1 Answer 1

1

Open the table tag before the foreach loop:

  <table>
    <tr>
      <td>MachineNo</td>
      <td>Make</td>
       .... Add rest of the header items like above
    </tr>

Start the foreach:

    foreach( $item as $value )
    {        
       echo "<tr>";

       $nos = $value->getElementsByTagName("MachineNo");
       $no  = $nos->item(0)->nodeValue;
       $machineno = str_replace( "1007-", "", $no );

       echo "<td>$machineno</td>";
       //.. Likewise, add rest of the td's after processing each node

      echo "</tr>";

     }

Close your table:

     </table>
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.