error code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pharasun
Forum Newbie
Posts: 3
Joined: Thu May 12, 2005 4:01 am

error code

Post 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
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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 :)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
Post Reply