title: Dynamic Table Rows with PHPWord
body: <p>I am hoping someone can help me because I am attempting to do something that is beyond my limits, I don't even know if a function exists for this within PHP or MySQL so my search on google hasn't been very productive.</p>
  
  <p>I am using PHPWord with my PHP/MySql Project, the intention is that I want to create a word document based on a template.</p>
  
  <p>I have used this <a href="http://jeroen.is/phpword-templates-with-repeating-rows/" rel="nofollow">guide</a> which is also on stack exchange.</p>
  
  <p>However this approach requires that the number of rows and the values are hard coded, i.e. in his example he has used cloneRow('first_name', 3), which then clones the table to have 3 rows, and then goes on to manually define the tags, i.e. </p>
  
  <pre><code>$doc-&gt;setValue('first_name#1', 'Jeroen');
  $doc-&gt;setValue('last_name#1', 'Moors');
  $doc-&gt;setValue('first_name#2', 'John');
  </code></pre>
  
  <p>I am trying to make this dynamic, in my instance I am trying to make a timetable, and one of the child tables is exactly that, so the query I have looks up how many entries there are and then collects a count of them, this $count is then used to dynamically create the correct number of rows.  This is the count I am using:</p>
  
  <pre><code>$rs10 = CustomQuery("select count(*) as count FROM auditplanevents where AuditModuleFk='" . $result["AuditModulePk"]."'"); 
  $data10 = db_fetch_array($rs10);
  $Count = $data10["count"];
  </code></pre>
  
  <p>I then use this <code>$document-&gt;cloneRow('date', $Count);</code> to executive the clonerow function, which works great and my document now looks something like <a href="http://prntscr.com/7b2ivz" rel="nofollow">this</a>.</p>
  
  <p>So, so far so good.</p>
  
  <p>What I now want is for a way to then append each row value of the query into the document, so rather than manually setting the tag value i.e. <code>$doc-&gt;setValue('first_name#1', 'Jeroen');</code> I could use something like <code>$doc-&gt;setValue('first_name#1', '$name from row 1');</code>  I suspect this will involve a foreach query but not too sure.</p>
  
  <p>I hope the above makes sense, but please feel free to ask me for anything else and become my personal hero.  Thanks</p>
  
  <p>Update: Just for sake of clarity, what I would like is for the output to look something like this:</p>
  
  <p>In my example are 5 results and therefore 5 rows created, I want to set values in following way:</p>
  
  <pre><code>${$date1} = date column from query 1st row
  ${$date2} = date column from query 2nd row
  ${$date3} = date column from query 3rd row
  ${$date4} = date column from query 4th row
  ${$date5} = date column from query 5th row
  </code></pre>