Search code examples
phpcodeigniterfpdf

Report where id


I'm having trouble printing data based on ID, error :

Too few arguments to function M_order::cetak_db_order(), 0 passed in C:\xampp\htdocs.......\Order.php on line 162 and exactly 1 expected

submit id

<td class="text-center"><a href="<?php echo base_url(); ?>backend/order/cetak_order/<?php echo $m->id_service; ?>" class="btn bg-navy btn-flat margin">Detail order</a></td>

Model code

 public function cetak_db_order($id){
    $hasil=$this->db->query("
        SELECT id_service,kd_cs,nama_cs,reciver_name,tanggal,status,nama_kecamatan AS tujuan, nama_kabupaten AS asal 
        FROM service s
        INNER JOIN customers c ON s.id_cs=c.id_cs 
        INNER JOIN kabupaten k ON s.id_origin=k.id_kab 
        INNER JOIN kecamatan p ON p.id_kec=s.id_destination WHERE id_service='$id'");
    return $hasil->result();
}

Controller code

public function cetak_order(){
    $pdf = new FPDF('l','mm','A5');
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);

    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(20,6,'Nama',1,0);
    $pdf->Cell(85,6,'penerima',1,0);
    $pdf->Cell(27,6,'asal',1,0);
    $pdf->Cell(25,6,'tujuan',1,1);
    $cetakorder = $this->M_order->cetak_db_order();
    foreach ($cetakorder as $row){
        $pdf->Cell(20,6,$row->nama_cs,1,0);
        $pdf->Cell(85,6,$row->reciver_name,1,0);
        $pdf->Cell(27,6,$row->asal,1,0);
        $pdf->Cell(25,6,$row->tujuan,1,1); 
    }
    $pdf->Output();
}

Solution

  • You are passing $m->id_service from the anchor Tag in HTML. But you are not using it anywhere in the PHP.

    You need to update your cetak_order function like below:

    public function cetak_order( $id ){
    .
    .
    .
    .
    .
    $cetakorder = $this->M_order->cetak_db_order( $id );
    
    

    Also you need to make sure to pass $id to cetak_order method from wherever you are calling it, unless it is passed automatically by your router.