I really hope that someone can help me!
I'm trying to create a pdf file with some data that I get from a query, the pdf creator is in the controller.
Here is my model:
function assistiti()
{
$user = $this->ion_auth->user()->row();
$userId = $user->id;
$query = $this->db->get_where('assistiti', array('assistito_da' => $userId));
return $query->result();
}
That I call from the controller:
$data['assistiti'] = $this->assistiti_m->assistiti();
In the same controller I create the pdf file with a foreach loop through data:
foreach($data as $post){
$nome = $post->nome;
$cognome = $post->cognome;
$tribunale = $post->tribunale;
$tbl .= '<tr><td style="border:1px solid #000;text-align:center">'.$nome.'</td>';
$tbl .= '<td style="border:1px solid #000;text-align:center">'.$cognome.'</td>';
$tbl .= '<td style="border:1px solid #000;text-align:center">'.$tribunale.'</td> </tr>';
;}
$pdf->writeHTML($tbl_header.$tbl.$tbl_footer , true, false, false, false, '');
and obviously it does't work...it returns to me a classic Trying to get property of non-object
and the only way that I found to return some data is putting the array index like that:
$nome = $post[0]nome;
$cognome = $post[0]->cognome;
$tribunale = $post[0]->tribunale;
but obviously it returns me only the first row.
Here is a print_r of $data
:
Array ( [assistiti] => Array ( [0] => stdClass Object ( [id_assistiti] => 1 [nome] => Matte [cognome] => Dama [luogo_nascita] => Milano [data_nascita] => 1986-10-01 [residenza] => Milano [dimora] => Milano [telefono] => 545431453143 [tribunale] => Milano) [1] => stdClass Object ( [id_assistiti] => 2 [nome] => dario [cognome] => vozzi [luogo_nascita] => 0 [data_nascita] => 0000-00-00 [residenza] => pesaro [dimora] => [telefono] => [tribunale] => ancona ) ) )
How can I get all the entries???
Thank you in advance!