Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-08-2012, 10:02 AM
PM User |
#1
New Coder
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
CReate Multiple PDF Documents With Mysql Table And PHP
Hi I'm trying to run a script that creates a .pdf statement for all files in the database, i've managed to run the file but it on create one document, now i have tested and changed, please can you assist to see why it only dump one record and not all individually.
PHP Code:
error_reporting ( E_ALL );
define ( 'FPDF_FONTPATH' , 'font/' );
require( 'mytable.php' );
//Connect to database
{
//query first table data for dbt info
mysql_connect ( 'localhost' , 'root' , '' );
mysql_select_db ( 'shackelton' );
$query1 = "select sfref ,clnname, clrefnumber from accdet ORDER BY sfref ASC " ;
$result = mysql_query ( $query1 );
while ( $row = mysql_fetch_assoc ( $result ));
{
// echo $row['id'] . " - " . $row['weight2'] . " - " . $row['pricect'] . "\n";
//runs the table data query from 1st table
$sfrefs = $row [ 'sfref' ];
$ot = ( $row [ 'sfref' ]. ".pdf" );
mysql_connect ( 'localhost' , 'root' , '' );
mysql_select_db ( 'shackelton' );
$query = "select sfref AS 'Reference',tdate AS 'Date', transact AS 'Description', amount AS 'Amount' from transa WHERE sfref = '$sfrefs'" ;
$resul1 = mysql_query ( $query );
}
class PDF extends PDF_MySQL_Table
{
}
$pdf =new PDF ();
$pdf -> Open ();
$pdf -> AddPage ();
$pdf -> SetFont ( 'Arial' , '' , 10 );
//First table: put all columns automatically
$pdf -> Ln ( 5 );
$pdf -> Cell ( 25 , 5 , 'Ref No' , 0 );
$pdf -> Cell ( 70 , 5 , $sfrefs , 0 );
$pdf -> Ln ( 10 );
$pdf -> SetFont ( 'Arial' , '' , 10 );
$pdf -> Table ( $query );
$pdf -> Ln ( 40 );
$pdf -> Output ( $ot , 'F' );
}
02-08-2012, 10:07 AM
PM User |
#2
Regular Coder
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
try taking the mysql_connect & mysql_select_db out of the loop...
you already have a connection don't re-connect
Users who have thanked jmj001 for this post:
02-08-2012, 10:16 AM
PM User |
#3
New Coder
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
my apologies, still only one record i know its something small, but for some reason can't find the fault.
PHP Code:
error_reporting ( E_ALL ); define ( 'FPDF_FONTPATH' , 'font/' ); require( 'mytable.php' ); //Connect to database { mysql_connect ( 'localhost' , 'root' , '' ); mysql_select_db ( 'shackelton' ); $query1 = "select sfref ,clnname, clrefnumber from accdet ORDER BY sfref DESC " ; $result = mysql_query ( $query1 ); while ( $row = mysql_fetch_assoc ( $result )) { // echo $row['id'] . " - " . $row['weight2'] . " - " . $row['pricect'] . "\n"; $sfrefs = $row [ 'sfref' ]; $ot = ( $row [ 'sfref' ]. ".pdf" ); mysql_connect ( 'localhost' , 'root' , '' ); mysql_select_db ( 'shackelton' ); $query = "select sfref AS 'Reference',tdate AS 'Date', transact AS 'Description', amount AS 'Amount' from transa WHERE sfref = '$sfrefs'" ; $resul1 = mysql_query ( $query ); } class PDF extends PDF_MySQL_Table { function Header () { //Title $this -> SetFont ( 'Arial' , '' , 12 ); $this -> Image ( 'GL.jpg' , 15 , 6 , 15 , 'L' ); $this -> Cell ( 0 , 6 , 'Statement Of Account' , 0 , 1 , 'C' ); $this -> Ln ( 10 ); //Ensure table header is output parent :: Header (); } } $pdf =new PDF (); $pdf -> Open (); $pdf -> AddPage (); $pdf -> SetFont ( 'Arial' , '' , 10 ); //First table: put all columns automatically $pdf -> Ln ( 5 ); $pdf -> Cell ( 25 , 5 , 'Ref No' , 0 ); $pdf -> Cell ( 70 , 5 , $sfrefs , 0 ); $pdf -> Ln ( 10 ); $pdf -> SetFont ( 'Arial' , '' , 10 ); $pdf -> Table ( $query ); $pdf -> Ln ( 40 ); $pdf -> Output ( $ot , 'F' ); }
02-08-2012, 10:26 AM
PM User |
#4
Regular Coder
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
i can't see anywhere in the loop where you are calling the pdf creation function
02-08-2012, 10:47 AM
PM User |
#5
New Coder
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
The pdf is called from the class. My mistake forgot to remove connection in second post
02-08-2012, 10:58 AM
PM User |
#6
Regular Coder
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
after the while loop add print_r like below and tell me what you get...
PHP Code:
error_reporting ( E_ALL );
define ( 'FPDF_FONTPATH' , 'font/' );
require( 'mytable.php' );
//Connect to database
{
mysql_connect ( 'localhost' , 'root' , '' );
mysql_select_db ( 'shackelton' );
$query1 = "select sfref ,clnname, clrefnumber from accdet ORDER BY sfref DESC " ;
$result = mysql_query ( $query1 );
while ( $row = mysql_fetch_assoc ( $result ))
{
// echo $row['id'] . " - " . $row['weight2'] . " - " . $row['pricect'] . "\n";
$sfrefs = $row [ 'sfref' ];
$ot = ( $row [ 'sfref' ]. ".pdf" );
$query = "select sfref AS 'Reference',tdate AS 'Date', transact AS 'Description', amount AS 'Amount' from transa WHERE sfref = '$sfrefs'" ;
$resul1 = mysql_query ( $query );
}
print_r ( $resul1 );
02-08-2012, 05:41 PM
PM User |
#7
New Coder
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
The result is displayed as
Resource id #9
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 12:42 AM .
Advertisement
Log in to turn off these ads.