I'm fairly new to PHP and was wondering how I could output this information into one table.
<?php
$url='mysite.com';
$content = simplexml_load_file($url);
foreach ($content->children() as $alarm) {
$severity = $alarm['severity'];
$id = $alarm ['id'];
echo "<table boarder=1>";
echo "<tr><th>Header1</th><th>ID</th><th>Header2</th><th>Header3</th><th>Header4</th> <th>Header5</th></tr>";
echo "<td style=\"text-align:center\" width=100px >";
echo $severity;
echo "</td><td style=\"text-align:center\" width=100px >";
echo $id;
echo "</td><td style=\"text-align:center\" width=100px >";
echo $alarm->nodeId;
echo "</td><td style=\"text-align:center\" width=100px >";
echo $alarm->nodeLabel;
echo "</td><td style=\"text-align:center\" width=100px >";
echo $alarm->lastEventTime;
echo "</td><td style=\"text-align:center\" width=500px >";
echo $alarm->logMessage;
echo "</td>";
echo "</table>";
}
?>
This is the output...
Header1 Header2 Header3 Header4 Header5** $severity $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage Header1 Header2 Header3 Header4 Header5 $severity $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage Header1 Header2 Header3 Header4 Header5 $severity $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage
The html output is as follows...
<table boarder="1">...</table>
<table boarder="1">...</table>
<table boarder="1">...</table>
<table boarder="1">...</table>
I just want it so it is in one table with the headers only on the top.
Header1 Header2 Header3 Header4 Header5** $severity[0] $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage $severity[1] $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage $severity[2] $id $alarm->nodeID $alarm->$nodeLabel $$alarm->logmessage
Any suggestions on how to get this information all into one table or best practices would be great.
tableinside thefor loopthe number of elements present would be the number of table's formed coz of iteration. Hence you should print table tag & its table head i.e. firsttrtag before for loop starts and close thetabletag after for loop end, and within theforloop you should only keep that code which is meant to iterate and print each row