FPDF, die Generierung von pdf aus mysql-Tabelle für den ausgewählten Wert

Hallo Freunde unten ist mein php-code erzeugt PDF aus MYSQL-Tabelle(für alle Zeilen) und ist wie alles, was ich brauche, ist das generieren von berichten für ausgewählte Zeilen nur sagen, dass zum Beispiel Zeile 1 und Zeile 3 gespeichert, die in einem array ( $sel), ich weiß nicht, wie zu erreichen, diese mit for, foreach und while-Schleife... jede Hilfe wäre sehr geschätzt.

Hier ist meine Datenbank-Tabelle

 ----------------------------------
| id | company            | total  |
 ----------------------------------
| 1  | ABC                | 1000   |
| 2  | XYZ                |  500   |
| 3  | PZX                |  100   |
 ----------------------------------

dies ist mein php-Seite, die erzeugt pdf-Datei beim laden und liefern den download-link für die Datei

<?php

require('u/fpdf.php');//fpdf path
include_once('db_connect.php');//my db connection

$sel = array (1,3);

$result=mysql_query("select * from `receipt`  ");

//Initialize the 3 columns and the total
$c_code = "";
$c_name = "";
$c_price = "";
$total = 0;

//For each row, add the field to the corresponding column
while($row = mysql_fetch_array($result))
{ 
   $code =$row['id'];
   $name = substr($row['company'],0,20);
   $real_price = $row['total'];
   $show =$row['total'];

 $c_code = $c_code.$code."\n";
 $c_name = $c_name.$name."\n";
 $c_price = $c_price.$show."\n";

//Sum all the Prices (TOTAL)
    $total = $total+$real_price;
}
mysql_close();

$total = $total;

//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();

//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY(26);
$pdf->SetX(45);
$pdf->MultiCell(20,6,$c_code,1);
$pdf->SetY(26);
$pdf->SetX(65);
$pdf->MultiCell(100,6,$c_name,1);
$pdf->SetY(26);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$c_price,1,'R');
$pdf->SetX(135);
$pdf->MultiCell(30,6,'$ '.$total,1,'R');

$filename="invoice.pdf";
$pdf->Output($filename,'F');

echo'<a href="invoice.pdf">Download your Invoice</a>';

?>

den obigen code gibt mir Ergebnis wie dieses-

 ----------------------------------
| 1  | ABC                | 1000   |
| 2  | XYZ                |  500   |
| 3  | PZX                |  100   |
 ----------------------------------
                          | 1600   |
                           --------

möchte ich mein Ergebnis angezeigt, wie dies

 ----------------------------------
| 1  | ABC                | 1000   |
| 3  | PZX                |  100   |
 ----------------------------------
                          | 1100   |
                           --------

wieder einmal vielen Dank im Voraus..

InformationsquelleAutor Praveen | 2013-11-18
Schreibe einen Kommentar