Forum


Replies: 7   Views: 217
Create a while loop in php to create a table
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 admin  · 15-05-2019 - 11:44

Hello,

We are not sure if we understand your question correctly. If you just need to create tables from an array you can just any loop function: for, while, foreach... ; phpdocx allows using any data source (databases, web services, strings, CSV...)

In the package you can find samples about how to generate a new table, for example:

// get the data for the database using PDO functions, an ORM or any other code
$data = ...;

// iterate the previous data to generate and add each new table
$i = 0;
while ($i < count($data)) {
  $valuesTable = $data[$i]; // an array structure
  $paramsTable = array(
      'border' => 'single',
      'tableAlign' => 'center',
      'borderWidth' => 10,
      'borderColor' => 'B70000',
      'tableWidth' => array('type' =>'pct', 'value' => 0),
  ); // add the needed table properties
  $docx->addTable($valuesTable, $paramsTable);
  $i++;
}

We recommend you to check and run the included samples and the documentation available on addTable.

Regards.