Import data with mysql connection
Added by Hervé RIEU over 9 years ago
Hi Andrei,
Fpdf_table work well but I have 3 questions
My pdf is hidden on http://www.haut-couserans.com/sitepro/animationphp/fpdf_table/animationmois.php
the php code is
$aCustomConfiguration = array(
'TABLE' => array(
'TABLE_ALIGN' => 'C',
'TABLE_LEFT_MARGIN' => 0, //left align
), );
$oTable->initialize( array( 40, 20, 17, 17, 17, 60), $aCustomConfiguration);
$aHeader = array(
array(
'TEXT' => "Titre de l'animation"
),
array(
'TEXT' => "Illustration"
),
array(
'TEXT' => 'Commune'
),
array(
'TEXT' => "Quand ?"
),
array(
'TEXT' => "A quelle Heure ?"
),
array(
'TEXT' => 'Description'
)
);
//add the header row
$oTable->addHeader( $aHeader );
$aImageCell = array(
'TYPE' => 'IMAGE',
'FILE' => PDF_APPLICATION_PATH . '/images/dice.jpg',
'WIDTH' => 10
);
$link = mysql_connect('xxxx','xxxxx','xxxxx');
mysql_select_db('hautcouserans');
$animationmois = '8';
$animationonline = '1';
$query = sprintf("SELECT *, DATE_FORMAT(animation_date_debut, ' %%d-%%m-%%Y') AS animation_date_debut FROM communes INNER JOIN animation ON communes.commune_id = animation_commune WHERE animation_online = 1 order by animation_date_debut limit 0,50", mysql_real_escape_string($animationmois), mysql_real_escape_string($animationonline)); $result = mysql_query($query, $link); if ($result) { while($row = mysql_fetch_array($result)) {
//row 1 - add data as Array
$aRow = Array();
$aRow[ 0 ][ 'TEXT' ] = $row['animation_titre_fr'];
$aRow[ 1 ] = array(
'TYPE' => 'IMAGE',
'FILE' => PDF_RESOURCES_IMAGES . '/dice.jpg',
'WIDTH' => 10
);
$aRow[ 2 ][ 'TEXT' ] = $row['commune_nom']; $aRow[ 3 ][ 'TEXT' ] = $row['animation_date_debut']; $aRow[ 3 ][ 'BACKGROUND_COLOR' ] = $aColor[ 1 ]; $aRow[ 4 ][ 'TEXT' ] = $row['animation_date_debut']; $aRow[ 5 ][ 'TEXT' ] = $row['commune_nom'];
$aRow[ 5 ][ 'BACKGROUND_COLOR' ] = $aColor[ 1 ];
//add the row to the table $oTable->addRow($aRow); } } else { echo mysql_error(); }
//add the data row
$oTable->addRow( $aRow );
Example pdf http://www.haut-couserans.com/sitepro/animationphp/fpdf_table/example-table-1-overview.php
-- I have 6 columns and when I change animation_date_debut on row4 to animation_heuredebut.
Send this message:
Notice: Undefined property TEXT in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Abstract.php on line 365
FPDF error: Some data has already been output, can't send PDF file
-- I have the same problem when I want to import Long text form database (with , etc...)
Notice: Undefined property aDefaultValues in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Abstract.php on line 365
Warning: array_keys() expects parameter 1 to be array, null given in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Empty.php on line 42
-- I would like to import image from my own data base. I don't understand where I can change image path ? Image are upload on a server file from KCfinder
$aImageCell = array(
'TYPE' => 'IMAGE',
'FILE' => PDF_APPLICATION_PATH . '/images/dice.jpg',
'WIDTH' => 10
);
Thank you
Hervé
Replies (6)
RE: Import data with mysql connection - Added by Andrei Bintintan over 9 years ago
Hervé RIEU wrote:
-- I have 6 columns and when I change animation_date_debut on row4 to animation_heuredebut.
Send this message:
Notice: Undefined property TEXT in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Abstract.php on line 365
FPDF error: Some data has already been output, can't send PDF file-- I have the same problem when I want to import Long text form database (with , etc...)
Notice: Undefined property aDefaultValues in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Abstract.php on line 365
Warning: array_keys() expects parameter 1 to be array, null given in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Empty.php on line 42
With these errors, you definitely do something wrong with
$aRow[ 4 ][ 'TEXT' ] = $row['animation_date_debut'];
The same when you set Long text.
This error:
Warning: array_keys() expects parameter 1 to be array, null given in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Empty.php on line 42
means that you don't set the $aRow[ 4 ][ 'TEXT' ] property for a cell, that you somehow try to generate an empty cell.
You set the data wrongly for the table, but where exactly I cannot tell by the code you've sent.
-- I would like to import image from my own data base. I don't understand where I can change image path ? Image are upload on a server file from KCfinder
$aImageCell = array(
'TYPE' => 'IMAGE',
'FILE' => PDF_APPLICATION_PATH . '/images/dice.jpg',
'WIDTH' => 10
);
Save the file to a temporary file and add it to the cell
$fileName = tempnamp(sys_get_temp_dir());
file_put_content($fileName, $databaseResult['image']);
$aImageCell = array(
'TYPE' => 'IMAGE',
'FILE' => $fileName
'WIDTH' => 10
);
... generate the table ... and also delete the $fileName
Regards, Andrei.
RE: Import data with mysql connection - Added by Hervé RIEU over 9 years ago
Hi Andrei,
Thank you for reply,
With these errors, you definitely do something wrong with
$aRow[ 4 ][ 'TEXT' ] = $row['animation_date_debut'];
When I wrote $aRow[ 4 ][ 'TEXT' ] = $row['animation_date_debut'];
the PDF File is Ok
but when I wrote $aRow[ 4 ][ 'TEXT' ] = $row['animation_heuredebut'];
I have this message
Notice: Undefined property TEXT in /home/hautcous/www/sitepro/animationphp/fpdf_table/classes/Pdf/Table/Cell/Abstract.php on line 365
FPDF error: Some data has already been output, can't send PDF file
If I write
$aRow[2]['TEXT'] = $row['commune_nom'];
$aRow[3]['TEXT'] = $row['animation_date_debut'];
$aRow[4]['TEXT'] = $row['animation_date_debut'];
$aRow[5]['TEXT'] = $row['animation_type_fr'];
The pdf is ouput like http://www.haut-couserans.com/sitepro/animationphp/fpdf_table/animationmois.php
I don't understand what is the problem ?
thank to help me
Hervé
RE: Import data with mysql connection - Added by Andrei Bintintan over 9 years ago
I assume that $row['animation_heuredebut'] does not exists or it is not a string.
Do a var_dump($row['animation_heuredebut']) to see it's value.
If it's NULL (might be null in the database) that is not OK as well.
or try: $aRow[ 4 ][ 'TEXT' ] = (string) $row['animation_heuredebut'];
RE: Import data with mysql connection - Added by Hervé RIEU over 9 years ago
It's work with $aRow[ 4 ][ 'TEXT' ] = (string) $row['animation_heuredebut'];
thank you
Now I will try to fix for the image
Hervé
RE: Import data with mysql connection - Added by Hervé RIEU over 9 years ago
Hi Andrei,
I don't find the file where is possible to change the position of the table when a new page is create. In my page 2 the table is too high on the top.
And I don't understand the modification for image path
Thank
Hervé
RE: Import data with mysql connection - Added by Andrei Bintintan over 9 years ago
Hervé RIEU wrote:
Hi Andrei,
I don't find the file where is possible to change the position of the table when a new page is create. In my page 2 the table is too high on the top.
The top position on a new page is given by the pdf page top margin. Please check that setting.
And I don't understand the modification for image path
You have to do the following steps:
- save you image from the database into a temporary file.
- create a image cell with this file
- add the cell to the table
- after the table is generated, delete the temporary file.