FPDF,从mysql表生成pdf以获取所选值

Hello friends below is my php code which generates PDF from MYSQL table(for all rows) and is working like anything, what i need is to generate report for selected rows only say for example row 1 and row 3 which is stored in an array ( $sel), i don't know how too achieve this using for, foreach and while loop... any help would be highly appreciated.

Here is my database table

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

this is my php page which generates pdf while loading and provide download link for that file

<?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."
";
 $c_name = $c_name.$name."
";
 $c_price = $c_price.$show."
";

//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>';

?>

the above code is giving me result like this-

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

i want my result to display like this

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

once again thanks in advance..

$result=mysql_query("select * from `receipt` where id IN(1,3) ");

following code works well after little modification in bove code (using where clause)

$result=mysql_query("select * from `receipt` where id IN(1,3) "); 

one can use as many as variable by seperating it using implode, for example selected checkbox array value from previous page

<?php

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

$sel =array (1,3);// can use $sel =$_GET['sel']; where $_GET['sel'], sel is a checkbox array value received from prev page..

$id=implode(",",$sel);//seperating ',' from array

$result=mysql_query("select * from `receipt` where id IN($id) ");
//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."
";
 $c_name = $c_name.$name."
";
 $c_price = $c_price.$show."
";

//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>';

?>