Return multiple lines in PDF

Asked

Viewed 26 times

0

Good afternoon, you guys!

I have a question about creating tables in my domPDF. It turns out that I gave a GROUP BY in the SELECT of my bank, but only returns me the first line, I wanted to list all the lines referring to that client... Code just below.

Model:

function fetch_single_details($customer_id)
{
          $datas = '20/02/2019';
          $sql = $this->db->select('*')
            ->from('horas h')
            ->join('cliente c','h.cliente = c.nome')
            ->group_by('cliente')
            ->where('cliente', $customer_id)
            ->get()
            ->result_array();
$data = $sql;
foreach($data as $element){
    $result[$element['cliente']][] = $element;

}

$output = '<h1 align="center" style="margin-top: 20%;"> TIME SHEET</h1>';
$output .= '<table width="100%" cellspacing="2" cellpadding="2">';

$date = [];
    foreach($result as $key=>$value){
        $date[] = [
            'cliente'=> $key,
            'item' => $value
        ];
    }
foreach($value as $row)
{

$output .= '
<tr>

    <td style="line-height: 0.3;">
    <p style="line-height: 1.5; font-size: 25px;"><b>CODE: </b>'.$row['codigo'].'</p>
    <p style="line-height: 0.1;">CLIENT: '.$row['cliente'].'</p>
    <p style="line-height: 0.1;">CNPJ: '.$row['regis'].'</p>
    <p style="line-height: 0.01;">WORKER: '.$row['nome_user'].'</p>
    <p style="line-height: 0.01;">WORKER PACKAGE : '.$row['pacote'].'</p>
    <p style="line-height: 0.01;">FROM: '.$datas. ' TO: </p>
    </td>
</tr>
</table>
<table class="table table-striped">
    <thead class="thead-dark">
        <tr>
            <th>Work Package</th>
            <th>Client</th>
            <th>Main Project</th>
            <th>Hours</th>
        </tr>
    </thead>';
 for($i = 0; $i < $row['id']; $i++){
    $output .=   '<tbody>
        <tr>
            <th>'.$row['pacote'].'</th>
            <th>'.$row['cliente'].'</th>
            <th>'.$row['projeto'].'</th>
            <th>'.$row['hrWork'].'</th>
        </tr>
    </tbody>
';
 }  
}
$output .= '

';
$output .= '</table>';
return $output;
}

}

  • Diêgo, I suggest you make a second select before the loop for filtering the data by your customer.

  • Could you detail how I would do that?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.