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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.