 <p>You are saving your model query results in a specific key(assistiti) inside the array $data, and then you are fetching the whole array in the foreach loop. This way, you got to loop through the specific array, inside the array $data:</p> <pre><code>foreach($data['assistiti'] as $post){ $nome = $post-&gt;nome; $cognome = $post-&gt;cognome; $tribunale = $post-&gt;tribunale; $tbl .= '&lt;tr&gt;&lt;td style="border:1px solid #000;text-align:center"&gt;'.$nome.'&lt;/td&gt;'; $tbl .= '&lt;td style="border:1px solid #000;text-align:center"&gt;'.$cognome.'&lt;/td&gt;'; $tbl .= '&lt;td style="border:1px solid #000;text-align:center"&gt;'.$tribunale.'&lt;/td&gt; &lt;/tr&gt;'; ;} $pdf-&gt;writeHTML($tbl_header.$tbl.$tbl_footer , true, false, false, false, ''); </code></pre>