开发者

How to generate PDF in PHP with Mysql while getting a Array of Values by GET or POST method?

开发者 https://www.devze.com 2023-04-11 08:02 出处:网络
<?php require(\'mysql_report.php\'); $checkbox = $_GET[\'checkbox\']; //geting Array of values from GET methode
<?php
require('mysql_report.php');
$checkbox = $_GET['checkbox'];
//geting Array of values from GET methode 
开发者_C百科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();
?>

here is the code i got the array of values from $_GET['checkbox']; how i got the pdf while the selected check boxes


You have placed the pdf generation code inside the foreach loop. It should be outside. Try this:

$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();

This should give you the correct output :)

0

精彩评论

暂无评论...
验证码 换一张
取 消