I’m getting the XML attributes for sky_condition from this XML file:
<METAR>
<sky_condition sky_cover="SCT" cloud_base_ft_agl="1600"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="2200"/>
</METAR>
Using the PHP code:
$sky = $xml->data->METAR[0]->sky_condition->attributes();
(I’ve removed extra XML code)
And I’m using this to output the data:
<table border="0">
<?php foreach ($sky as $sky_cover => $cloud_base_ft_agl){
echo"<tr>";
echo"<td><strong>";
if ($sky_cover == "CAVOK") {echo "Ceiling and Visibility OK";} else {echo $sky_cover;
}
echo"</strong></td>";
echo"<td><strong>";
if (isset($cloud_base_ft_agl)){echo $cloud_base_ft_agl; }
echo"</strong></td>";
echo"</tr>";
}?>
</table>
Is there anyway I could have the data displayed such as:
<table>
<tr>
<td><strong>SCT</strong></td>
<td><strong>1600</strong></td>
</tr>
<tr>
<td><strong>BKN</strong></td>
<td><strong>2200</strong></td>
</tr>
</table>
Just do this
See Demo
http://codepad.viper-7.com/A9pba4