I would like to be pointed in the right direction on how I would go about editing data (not headings) of a table using PHP DOM Document.
I have been looking into PHP DomDocument to replace the content of "Name 1" and "Age 1" etc, with real data from a database, however I am having a few issues...
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile('template.html');
$sql = 'SELECT name,
age
FROM db.people';
$sql = mysql_query($sql);
for($i=0; $person = mysql_fetch_assoc($sql); $i++)
{
$doc->getElementsByTagName('td')->item($i)->nodeValue = $person['name'];
}
$doc->formatOutput = TRUE;
echo $doc->saveHTML();
?>
I would like to continue editing the above PHP code to replace place holder data with data from a database.
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Stephanie</td>
<td>22</td>
</tr>
<tr>
<td>Martin</td>
<td>45</td>
</tr>
<tr>
<td>Sarah</td>
<td>61</td>
</tr>
<tr>
<td>Kevin</td>
<td>12</td>
</tr>
</table>
Can anyone point me in the right direction, and if i'm on the right track?