Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2012, 10:02 AM   PM User | #1
cswart777
New Coder

 
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
cswart777 is an unknown quantity at this point
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');    

cswart777 is offline   Reply With Quote
Old 02-08-2012, 10:07 AM   PM User | #2
jmj001
Regular Coder

 
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
jmj001 is an unknown quantity at this point
try taking the mysql_connect & mysql_select_db out of the loop...

you already have a connection don't re-connect
jmj001 is offline   Reply With Quote
Users who have thanked jmj001 for this post:
cswart777 (02-08-2012)
Old 02-08-2012, 10:16 AM   PM User | #3
cswart777
New Coder

 
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
cswart777 is an unknown quantity at this point
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(06'Statement Of Account'01'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');    

cswart777 is offline   Reply With Quote
Old 02-08-2012, 10:26 AM   PM User | #4
jmj001
Regular Coder

 
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
jmj001 is an unknown quantity at this point
i can't see anywhere in the loop where you are calling the pdf creation function
jmj001 is offline   Reply With Quote
Old 02-08-2012, 10:47 AM   PM User | #5
cswart777
New Coder

 
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
cswart777 is an unknown quantity at this point
The pdf is called from the class. My mistake forgot to remove connection in second post
cswart777 is offline   Reply With Quote
Old 02-08-2012, 10:58 AM   PM User | #6
jmj001
Regular Coder

 
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
jmj001 is an unknown quantity at this point
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); 
jmj001 is offline   Reply With Quote
Old 02-08-2012, 05:41 PM   PM User | #7
cswart777
New Coder

 
Join Date: Aug 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
cswart777 is an unknown quantity at this point
The result is displayed as
Resource id #9
cswart777 is offline   Reply With Quote
Reply

Bookmarks

Tags
mysql, pdf, php, statement

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:42 AM.


Advertisement
Log in to turn off these ads.