Page 1 of 1

error code

Posted: Thu May 12, 2005 9:33 pm
by Pharasun

Code: Select all

<?
require('fpdf.php');
class PDF extends FPDF
{
//Simple table
function BasicTable($header,$data)
{
//Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
//Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
}//end class

//header declare
$header=array('name','surname');

//data query from database keep to array 2 dimension
$hostname = "localhost"; 
$user = "root"; 
$password = ""; 
$dbname = "jnt";
$tblname = "jnt_bank";
mysql_connect($hostname,$user,$password) ;

mysql_select_db($dbname) or ("non");
$sql = "select * from member "; 
$dbquery = mysql_db_query($dbname,$sql);
$i=0;
while($arr) {
$data[$i][0] = $arr['name'];
$data[$i][1] = $arr['surname'];
$i++;
}

//create object pdf
$pdf = new PDF();
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->Output();
?>

output error is!

Warning: Invalid argument supplied for foreach() in c:\appserv\www\pdf\repmember_printpdf1.php on line 9

Warning: Invalid argument supplied for foreach() in c:\appserv\www\pdf\repmember_printpdf1.php on line 13
FPDF error: Some data has already been output, can't send PDF file

please help! me for correct code.

d11wtq | Please read the sticky about posting code in the forums :D

Posted: Thu May 12, 2005 9:56 pm
by SBro
I'm guessing $header and $data aren't arrays. Foreach loop needs an array to work with.

You should also post code the proper way :)

Posted: Fri May 13, 2005 4:04 am
by phpScott
seems that way, check out is_array() in the manual if it isn't an array then create it before passing it on otherwise it is an array just pass it on.