2011-10-06 40 views
2
<?php 
require('mysql_report.php'); 
$checkbox = $_GET['checkbox']; 
//geting Array of values from GET methode 
foreach ($checkbox as $value) 
    { 
    $sql="SELECT name,address,email,problem,reply_query FROM query where id = $value "; 
    $result = mysql_query($sql); 
    while($row = mysql_fetch_array($result)){ 

     } 
    $pdf = new PDF('L','pt','A4'); 
    $pdf->SetFont('Arial','',12); 
    $pdf->connect('localhost','uname','pwd','mydb'); 
    $attr = array('titleFontSize'=>18, 'titleText'=>'Report'); 

    $qry=$pdf->mysql_report($sql,false,$attr); 
    }  
$pdf->Output(); 
?> 

這裏是代碼我從$ _GET ['checkbox'];當選中的複選框時,我如何得到pdf如何在通過GET或POST方法獲取數組值的同時使用Mysql在PHP中生成PDF?

回答

1

您已將pdf生成代碼放入foreach循環中。它應該在外面。 試試這個:

$sql="SELECT name,address,email,problem,type,other,reply_query FROM query where"; 
$i = 1; 
foreach ($checkbox as $value) 
{ 
        if($i<count($checkbox)) 
        { 
        $sql=$sql." id = \"".$value."\" OR"; 
        $i++; 
        } 
        else 
        { 
        $sql=$sql." id = \"".$value."\""; 
        } 
}  

    $pdf = new PDF('L','pt','A4'); 

    $pdf->SetFont('Arial','',12); 
    $pdf->connect('localhost','root','asdfgh','Tree_help'); 
    $attr = array('titleFontSize'=>18, 'titleText'=>'Treehealth Report'); 
    $qry=$pdf->mysql_report($sql,$dump=false,$attr=array());   
    $pdf->Output(); 

這應該給你正確的輸出:)

+0

謝謝你,這是對我來說非常有用 – Naveenbos

相關問題