Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Klik link berikut untuk informasi cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

(SOLVED) Print preview fpdf

Sore mbah,
Saya lagi bikin report pake fpdf, ada kesulitan ni mbah.
Saya mau pake 2 hasil query buat di view di fpdfnya.

Hasil Query 1 ada 2 row, query 2 ada 8 row.
Antara query 1 & query 2 ada 1 filed yang saling berhubungan.

Saya mau hasilnya nanti :
Query1 (row 1) halaman 1
Query2 (row ada 7) halaman 2
Query1 (row2) halaman 3
Query2 (row ada 1) halaman 4

Cara saya yang sekarang :
foreach (query1) {
foreach (query2) {
}
}


Hasilnya
Query1 (row 1) halaman 1
Query2 (row ada 8) halaman 2
Query1 (row2) halaman 3
Query2 (row ada 8) halaman 4

Minta bantuannya mbah..

Comments

  • siapa mbah mu? zzz...
    emng syarat per halaman apa? ..
    kan tinggal nambahin "addPage();" ..
  • Saya lanjut ya mas.
    <?php
    $GLOBALS['lap_pdf'] = $lap_pdf;
    $GLOBALS['lap_pdf_ot'] = $lap_pdf_ot;
    $baru = new FPDF();
    $a = 210;
    $b = 69;
    $baru->FPDF('L','mm',array($a,$b));
    $baru->SetMargins(2.5,1,2.5);
    $baru->SetAutoPageBreak(true,0);
    $baru->AliasNbPages();
    $baru->AddPage();
     
    foreach ($array1 as $baris)
    {
    $baru->Ln(7);
    $baru->setFont('Arial','',5);
    $baru->Cell(15,2,'Name',0,0,'L');
    $baru->Cell(2,2,':',0,0,'C');
    $baru->Cell(130,2,$baris->nama_lengkap,0,0,'L');
    //..............
    $baru->AddPage();
    $baru->Ln(7);
     
    foreach ($array2 as $baris_ot)
    {
    $baru->setFont('Arial','',5);
    $baru->Cell(20,2,$baris_ot->tanggal,0,0,'C');
    $baru->Cell(20,2,$baris_ot->lama_ot,0,0,'C');
    //..............
    }
     
    $baru->AddPage();
    }
     
    $baru->Output("filename.pdf","I");
    exit;
    ?>

    Di halaman 1 nampilin array1[0]. Halaman kedua array2[]. Halaman 3 array[1].
    array 1 & 2 punya id yang sama.

    Saya maunya halaman 1 = array1[0], halaman 2 = array2 (Khusus yang idnya sama dengan array1[0].

    Halaman 3 = array1[1], halaman 4 = array2 (Khusus yang idnya sama dengan array1[1].
    Begitu seterusnya mas.

    Arraynya kaya gini:
    Array 1 :
    Array (
    [0] => stdClass Object ( [id] => 30 [nik] => 436 )
    [1] => stdClass Object ( [id] => 31 [nik] => 547 )
    )

    Array 2 :
    Array (
    [0] => stdClass Object ( [id] => 35 [id_struktur_gaji] => 30 [tgl] => 2017-03-16 [ot] => 04:00:00 )
    [1] => stdClass Object ( [id] => 33 [id_struktur_gaji] => 30 [tgl] => 2017-03-18 [ot] => 08:00:00 )
    [2] => stdClass Object ( [id] => 37 [id_struktur_gaji] => 30 [tgl] => 2017-03-20 [ot] => 02:00:00 )
    [3] => stdClass Object ( [id] => 39 [id_struktur_gaji] => 31 [tgl] => 2017-03-20 [ot] => 02:00:00 )
    [4] => stdClass Object ( [id] => 36 [id_struktur_gaji] => 30 [tgl] => 2017-03-21 [ot] => 02:00:00 )
    [5] => stdClass Object ( [id] => 34 [id_struktur_gaji] => 30 [tgl] => 2017-03-24 [ot] => 05:00:00 )
    [6] => stdClass Object ( [id] => 32 [id_struktur_gaji] => 30 [tgl] => 2017-03-25 [ot] => 12:00:00 )
    [7] => stdClass Object ( [id] => 38 [id_struktur_gaji] => 30 [tgl] => 2017-03-26 [ot] => 13:00:00 )
    )
  • edited April 2017
    itu data dari query bukan?
    klo iya.. logik gw begini
    $query1 = mysql_query("select id,field,yang,dibtuhkan from table1 ");
    $id_query1 = array();
    foreach ($query1 as $array1)
    {
    $id_query1[] = $array1->id;
    //bla..bla..bla
     
    }
     
    $pdf->addPage();
    $query2 = mysql_query("select id,field,yang,dibutuhkan from table2 where id_table1 in (".implode($id_query1,).") ";
    $id_query2 = array();
    foreach ($query2 as $array2)
    {
    $id_query2[] = $array2->id;
    //bla..bla..bla
     
    }
    $pdf->addPage();
     
    $query3 = mysql_query("select id,field,yang,dibutuhkan from table3 where id_table2 in (".implode($id_query2,).") ";
    $id_query3 = array();
    foreach ($query3 as $array3)
    {
    $id_query3[] = $array3->id;
    //bla..bla..bla
     
    }
  • ia bener mas dari query, uda solve mas saya pake penggabungan array. Makasih yaa
Sign In or Register to comment.