To accomplish that task using a template you can:
- Generate the table as a WordFragment and replace a placeholder in the template: https://www.phpdocx.com/api-documentation/templates/replace-variable-word-fragment-Word-document
- Use replaceTableVariable to add as many rows as needed in a existing table of a DOCX template:
$docx = new CreateDocxFromTemplate('template.docx'); $data = array( array( 'ITEM' => 'Product A', 'REFERENCE' => '107AW3', ), array( 'ITEM' => 'Product B', 'REFERENCE' => '204RS67O', ), array( 'ITEM' => 'Product C', 'REFERENCE' => '25GTR56', ), ); $docx->replaceTableVariable($data);
How to extract the information and generate an array from it depends on the function or method you are using to access the database: mysql functions, PDO, ORM...
We recommend you to check the included samples and the information available on the API pages of each method, that illustrate how to accomplish these kind of tasks.