Forum


Replies: 5   Views: 3505
Mysql and template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by lorepra  · 21-05-2012 - 10:35

I have this text stored in mysql, in a table temp:

[quote]Well, here it goes: $PIECHART$ This is a simple[/quote]

I retrieve it with this code:

[code]$query="select text from temp where uid=1";
$result = mysql_query($query,$connessione);
$row = mysql_fetch_assoc($result);
$doc0 = new CreateDocx();
$doc0->addText($row['text']);
$doc0->createDocx('doc0');

$doc1 = new CreateDocx();
$doc1->addTemplate('doc0.docx');
$doc1->addTemplateVariable('PIECHART', 'NEW VALUE');
$doc1->createDocx('doc1');[/code]

and the result is as expected, the placeholder PIECHART is replaced.
I got:
[quote]Well, here it goes: NEW VALUE This is a simple[/quote]

but with this code:
[code]
$query="select nome from temp where tessera=1";
$result = mysql_query($query,$connessione);
$row = mysql_fetch_assoc($result);
$doc0 = new CreateDocx();
$doc0->addText($row['nome']);
$doc0->createDocx('doc0');

$legends = array(
'legend1' => array(10, 11, 12),
'legend2' => array(30, 21, 12),
'legend3' => array(40, 41, 42)
);

$Chart1 =
array(
'data' => $legends,
'type' => 'pie3DChart',
'title' => 'Title',
'cornerX' => 20,
'cornerY' => 20,
'cornerP' => 30,
'color' => 2,
'textWrap' => 0,
'sizeX' => 10,
'sizeY' => 10,
'jc' => 'right',
'showPercent' => 1,
'font' => 'Times New Roman'
);

$doc1 = new CreateDocx();
$doc1->addTemplate('doc0.docx');
$doc1->addTemplateChart('PIECHART', $Chart1);
$doc1->createDocx('doc1');
[/code]

in this case the placeholder is not replaced by the chart.
What I got is:
[quote]Well, here it goes: $PIECHART$ This is a simple[/quote]

I work with linux, the filesystem is natively utf-8, mysql is still using utf-8 and also php.

Any help would be appreciated,

Posted by admin  · 11-04-2013 - 12:13

Hello,

Please try and check easy/Template_chart.php example included in the library.

Regards.

Posted by lorepra  · 11-04-2013 - 12:13

[quote][b]Quote from admin on May 21, 2012, 10:55[/b]
Hello,

Please try and check easy/Template_chart.php example included in the library.

Regards.[/quote]

The example works fine, the problem is involved with the retrieve of the text from mysql.

Regards.

Posted by lorepra  · 11-04-2013 - 12:13

[quote][b]Quote from admin on May 21, 2012, 10:55[/b]
Hello,

Please try and check easy/Template_chart.php example included in the library.

Regards.[/quote]

I've tried this way:

1) Opened the Template:[b] TemplateChart.docx[/b] used by the program easy/Template_chart.php
2) Copied the text of the template in mysql, in order to have the placeholder $PIECHART$ stored
3) modified the program
[code]<?php
require_once '../../classes/CreateDocx.inc';

mb_internal_encoding( 'UTF-8' );

// the intermediate file
$myfirstdoc = new CreateDocx();

$user = '###';
$user_password = '###';
$db_name = '###';

$conn = mysql_connect("localhost","$user","$user_password")or die("Connessione non riuscita: " . mysql_error());
mysql_select_db("$db_name", $conn) or die("Errore nella selezione del database");

mysql_query( "SET NAMES utf8", $conn );
mysql_query( "SET CHARACTER SET utf8", $conn );

$query="select nome from temp where tessera=1";

$result = mysql_query($query,$connessione);
$row = mysql_fetch_assoc($result);
$myfirstdoc = new CreateDocx();
$myfirstdoc->addText($row['nome']);
$myfirstdoc->createDocx('myfirstdoc');

// At this time "myfirstdoc.docx" should be equivalent to the original
Template used in the sample program: "../files/TemplateChart.docx"

// now begin the work on the final document

$docx = new CreateDocx();

//
// I use the first file as Template
//

$docx->addTemplate('myfirstdoc.docx');

$legends = array(
'legend1' => array(10, 11, 12),
'legend2' => array(30, 21, 12),
'legend3' => array(40, 41, 42)
);

$paramsChart =
array(
'data' => $legends,
'type' => 'pie3DChart',
'title' => 'Title',
'cornerX' => 20,
'cornerY' => 20,
'cornerP' => 30,
'color' => 2,
'textWrap' => 0,
'sizeX' => 10,
'sizeY' => 10,
'jc' => 'right',
'showPercent' => 1,
'font' => 'Times New Roman'
);

$docx->addTemplateChart('PIECHART', $paramsChart);

$docx->createDocx('../docx/template_chart');
[/code]


The result, using the "easy/Template_chart.php example included in the library"
is the same as above,
The placeholder $PIECHART$ is not replaced by the chart!!!


Posted by admin  · 12-04-2013 - 09:21

Hello,



Please try easy/Template_chart.php example without changing anything. And open the document to see if the chart is in it.



Regards.