Replies: 1   Views: 3452
How to create table using mysql and php - solved
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by mightycpa  · 19-04-2013 - 18:17


I wanted to create a table using a query on my php page.

I created a query that returns several rows of 3 columns.  I had trouble figuring out a way to format the results of the query so that they fit your syntax.  I understand your syntax to basically describe a table as an array that contains one array for each row to be included in the table:






Finally, I came up with this, and it works very well:

$sql = "SELECT A, B, C FROM WHEREVER";    

$result = mysql_query($sql) or die (mysql_error());


$rows_ra = array();

while ($row = mysql_fetch_assoc($result)) {

    foreach ($row as $key => $value) {

      $rows_ra[$i][$key] = $value;




$paramsTable = array(

'border' => 'single',

'border_sz' => 10


$docx->addTable($rows_ra, $paramsTable);


This is a big breakthrough for me!  Thanks for the tool!