I have the simplest of scripts to load TWO queries onto a TCPDF pdf file.
As the code stands it throws the following error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\gf3dataservices\tcpdf_5_9_207\tcpdf_table_1.1.0\tcpdf_table\xxxtemp1.php on line 48
TCPDF ERROR: Some data has already been output, can't send PDF file
This is Line 48
while ($data = mysql_fetch_array($result2))
I am basically running a query from my db and then trying to get a second test query to run and include on the output.
I can remove the section //First Query and Output and it will work and output the second query I can remove the section //Second Query and Output and it will work and output the first query
However I CANNOT keep them both in - it just wont work - driving me mad
<?php
require_once ('tcpdf/config/lang/eng.php');
require_once ('tcpdf/tcpdf.php');
require_once ('connection.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set font
$pdf->SetFont('times', '', 11);
// landscape
$pdf->addPage( 'L', 'LETTER' );
//First Query and Output
$result = mysql_query("CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');", $con);
$html = '
<table border="1" cellspacing="3" cellpadding="4">
<tr>
<th align="center"><b>a</b></th>
<th align="center"><b>b</b></th>
</tr></table>';
while ($data = mysql_fetch_array($result))
{
$html .= '<table border="1"><tr>
<td align="center">'.$data['CommisionPercentage'].'</td>
<td align="center">'.$data['Turnover'].'</td>
</tr></table> ';
}
$pdf->writeHTML($html, true, false, true, false, ''); //for generate
//Second Query and Output
$result2 = mysql_query("Select 1 as a, 2 as b");
$html = '
<table border="1" cellspacing="3" cellpadding="4">
<tr>
<th align="center"><b>a</b></th>
<th align="center"><b>b</b></th>
</tr></table>';
while ($data = mysql_fetch_array($result2))
{
$html .= '<table border="1"><tr>
<td align="center">'.$data['a'].'</td>
<td align="center">'.$data['b'].'</td>
</tr></table> ';
}
$pdf->writeHTML($html, true, false, true, false, ''); //for generate
$pdf->Output('FormPantauExpLocalAll', 'I'); // for generate pdf file
?>
SELECT 1 as a, 2 as b FROM ????
– jdstankosky 58 mins agomysql_*
functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you pick PDO here is a good tutorial. – War10ck 51 mins ago