title: DOM Document PHP Replace TD
body: <p>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.</p>
  
  <p>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...</p>
  
  <pre><code>&lt;?php
  
  $doc = new DOMDocument();
  $doc-&gt;loadHTMLFile('template.html');
  
  $sql = 'SELECT name,
                 age
          FROM db.people';
  
  $sql = mysql_query($sql);
  
  for($i=0; $person = mysql_fetch_assoc($sql); $i++)
  {
      $doc-&gt;getElementsByTagName('td')-&gt;item($i)-&gt;nodeValue = $person['name'];
  }
  
  $doc-&gt;formatOutput = TRUE;
  echo $doc-&gt;saveHTML();
  
  ?&gt;
  </code></pre>
  
  <p>I would like to continue editing the above PHP code to replace place holder data with data from a database.</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Age&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Stephanie&lt;/td&gt;
          &lt;td&gt;22&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Martin&lt;/td&gt;
          &lt;td&gt;45&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Sarah&lt;/td&gt;
          &lt;td&gt;61&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Kevin&lt;/td&gt;
          &lt;td&gt;12&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Can anyone point me in the right direction, and if i'm on the right track?</p>