Hi,

I am creating reports in my project using TCPDF. I want to get the reports on a daily basis. For an example if there are 10 transactions occurred in a day, i want to display them in a report format.

These are the 2 pages that i have created. The following error message displayed

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\MySite\php files\tcpdf\examples\transaction_report.php on line 37

while($row2 = mysql_fetch_array($this->result))

Call Stack

<form id="form1" name="form1" method="post" action="tcpdf/examples/transaction_report.php">
  <label>Transaction Reports<br />
  <br />
  DATE </label>
  <input type="text" id="demo3" name="" maxlength="25" size="25"/>
  <img src="../images/cal.gif" onclick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>
  <p>&nbsp;</p>
  <p>
    <label></label>
  </p>
  <p>&nbsp;</p>
  <p>
    <label>
    <a href="tcpdf/examples/transaction_report.php">
    <input type="submit" name="button" id="button" value="Generate" />
    </a>
    </label>
  </p>
</form>

transaction_report.php

<?php

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

    public function myconnection(){
	$this->con = mysql_connect("localhost","root",""); 

	$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date LIKE '". date("Y-m-d",time()) ."' ORDER BY tran_id");

	}

	// Colored table
	public function ColoredTable($header,$data) {
		// Colors, line width and bold font
		$this->SetFillColor(200, 128, 0);
		$this->SetTextColor(255);
		$this->SetDrawColor(128, 0, 0);
		$this->SetLineWidth(0.3);
		$this->SetFont('', 'B');
		// Header
		$w = array(18, 15, 32, 22, 30, 45);
		$num_headers = count($header);
		for($i = 0; $i < $num_headers; ++$i) {
			$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
		}
		$this->Ln();
		// Color and font restoration
		$this->SetFillColor(200, 200, 200);
		$this->SetTextColor(0);
		$this->SetFont('');
		// Data
		$fill = 0;
		while($row2 = mysql_fetch_array($this->result))
 		{
			$this->Cell($w[0], 6, number_format($row2['tran_id']), 0, 'L', $fill);
			$this->Cell($w[1], 6, number_format($row2['account_number']), 'LR', 0, 'L', $fill);
			$this->Cell($w[2], 6, $row2['transaction_type'], 'LR', 0, 'L', $fill);
			$this->Cell($w[3], 6, $row2['transaction_amount'], 'LR', 0, 'L', $fill);
			$this->Cell($w[4], 6, $row2['transaction_date'], 'LR', 0, 'L', $fill);
			$this->Cell($w[5], 6, $row2['approved_status'], 'LR', 0, 'L', $fill);
			$fill=!$fill;
		}
		$this->Cell(array_sum($w), 0, '', 'T');
	}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Mahapitiya Sanasa Bank');
$pdf->SetTitle('Daily Transaction Report');
$pdf->SetSubject('');
$pdf->SetKeywords('');

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 011', PDF_HEADER_STRING);

// set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'BI', 7);

// add a page
$pdf->AddPage();

// set some text to print
$txt = <<<EOD
Mahapitiya Sanasa Bank,
Mahapitiya,
Pothuhera
Tel:0372237295

Daily Transactions Report 


EOD;

// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);


//Column titles
$header = array('Tran ID', 'Account Number', 'Transaction Type', 'Transaction Amount', 'Transaction Date', 'Approved Status');

//Data loading
//$data = $pdf->LoadData('../cache/table_data_demo.txt');
$pdf->myconnection();

// print colored table
$pdf->ColoredTable($header,"");

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_011.pdf', 'I');
mysql_close($con);
?>
//============================================================+
// END OF FILE                                                
//============================================================+

Recommended Answers

All 5 Replies

This indicates an error in your query. See the sticky thread in this forum on how to check for errors.

What data type is your transaction_date column ?

How can i use the sticky thread?

The data type is "DATE"

If your column is of type date, you cannot use like on it (since it is a string function). Just do the following:

$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '". date("Y-m-d") ."' ORDER BY tran_id");

I have changed it, but still same error...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.