Jump to content

XML data to PHP HTML code


m88

Recommended Posts

Hi, I have a working PHP script that picks data from an XML file. I would like the script to pick values from certain range.

Right now the PHP shows every Item with name and value in a table. So when all 4 of the item values are shown they are beneath each other in a column.

But i would like them all to be next to each other. Therefore if i have these 4 item values (Name 0000), if i could pick them from the XML e.g. not the first but the second than i could make them manually with 4 different PHP scripts and put them next to each other.

 

I'm not very good at PHP, but i think this is probably very easy thing to do.

Thanks in advance.

 

The PHP script looks like this:

<?

  // DOMElement->getElementsByTagName() -- Gets elements by tagname
  // nodeValue : The value of this node, depending on its type.
  // Load XML File. You can use loadXML if you wish to load XML data from a string

  $objDOM = new DOMDocument();
  $objDOM->load("feed.xml"); //make sure path is correct


  $note = $objDOM->getElementsByTagName("item");

  // for each note tag, parse the document and get values for
  // tasks and details tag.

  foreach( $note as $value ){

  
    $places = $value->getElementsByTagName("name");
    $place  = $places->item(0)->nodeValue;

    $details = $value->getElementsByTagName("amount");
    $detail  = $details->item(0)->nodeValue;




    echo "<BODY STYLE='background-color:transparent'>

<table border='0'>
  <tr>
    <td width='127'><table width='127px' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td><p style='font-family:arial;color:white;font-size:22px;padding-left:3px;text-align:left;  background:url(bg2.png)'><strong> $place</strong></p></td>

</tr>

</table>
</td>
    <td width='115'>
      <table width='115px' border='0' cellpadding='0' cellspacing='0'>
        <tr>
          <td><p style='font-family:arial;color:white;font-size:22px;text-align:right;padding-right:5px; background:url(bg1.png)'><strong>$detail</strong></p></td>
          
        </tr>
        
</table></td>
  </tr>
  
</table>




";
$i++; }
?> 

 

And the XML looks like this:

<xml>
<item>
<name>Examplename</name>
<amount>0000</amount>
</item>
<item>
<name>Examplename</name>
<amount>0000</amount>
</item>
<item>
<name>Examplename</name>
<amount>0000</amount>
</item>
<item>
<name>DExamplename</name>
<amount>0000</amount>
</item>
</xml>

Link to comment
https://forums.phpfreaks.com/topic/236187-xml-data-to-php-html-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.