Categories > OpenTBS with DOCX >

MySQL->DOCX block with repeating records

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: M. Polat
Date: 2014-10-06
Time: 10:44

MySQL->DOCX block with repeating records

Hello
I am using the the following Query for a docx template. In this query I have many records per person and I want to have a block. I want to have a code in a docx page that create per person on one page. Than meand, when I have 10 persons (PId) then I will have a docx file with 10 pages.  For the next person it should add a second page an so on. The coloumn of personId is "PId".
Could please someone help me to create such a block? I am lost with the manuell. Or can someome give me some help where to read for such cases?

My Query: $TBS->MergeBlock('ml','mysql',"SELECT * FROM lohnpositionen Where RefId=$Id  Order BY PId, Flag");

MyBlock: [ml.Num;block=w:tr]    [ml.Art]    [ml.PId]    [ml.Menge]    [ml.Ansatz]    [ml.Total]

Thanks
mpol_ch
By: M. Polat
Date: 2014-10-06
Time: 14:46

Re: MySQL->DOCX block with repeating records

Just for additional Information. I am using now the following information but I am receiving no results. What am I doing wrong?

$TBS->LoadTemplate('tbs/vorlagen/vorlagelohn.docx');
$TBS->MergeBlock('main','mysql', 'SELECT PId,Num,Art,Flag,Prozent,Menge,Ansatz,Total  FROM lohnpositionen');
$TBS->MergeBlock('sub', 'mysql', 'SELECT Num,Art,Flag,Prozent,Menge,Ansatz,Total      FROM lohnpositionen WHERE (PId=%p1%)');

[main.PId;block=begin]
[sub.Num; p1=[main.PId]]
[main.PId;block=end]

and I am getting the following error:
TinyButStrong Error when merging block [sub]: MySql error message when opening the query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%p1%)' at line 1

TinyButStrong Error Show() Method: The output is cancelled by the OpenTBS plugin because at least one error has occured.

thanks
mpol_ch
By: M. Polat
Date: 2014-10-07
Time: 06:40

Re: MySQL->DOCX block with repeating records

Hello
I solved my problem witht the following code.

PHP Side:
 
$TBS->LoadTemplate('tbs/vorlagen/vorlagelohn.docx',OPENTBS_ALREADY_UTF8);

$TBS->MergeBlock('main','mysql', "SELECT PId,RefId,Datum,Vom,Bis,Monat,Jahr,Num,Art,Total  FROM loehne WHERE Monat=$Monat AND Jahr=$Jahr AND RefId=$Id ");
$TBS->MergeBlock('sub', 'mysql', "SELECT Num,Art,Flag,Prozent,Menge,Ansatz,Total      FROM lohnpositionen WHERE (PId ='%p1%') AND RefId=$Id");
$TBS->MergeBlock('subma','mysql', "SELECT maid,maanrede,maname,mavname,mastr,maplz,maort FROM mitarbeiter WHERE (maid ='%p1%')");

DOCX Side:
[main;block=begin]
                   
Personal-Nr:[main.PId]       
Datum:[main.Datum;frm=dd.mm.yyyy]


    [subma;block=begin;p1=[main.PId]]
    [subma.maanrede]
    [subma.maname] [subma.mavname]
    [subma.mastr]
    [subma.maplz] [subma.maort]  
    [subma;block=end]

[sub.Num;block=w:tr;p1=[main.PId]]    [sub.Art]    [sub.Prozent]    [sub.Menge]    [sub.Ansatz]    [sub.Total]

[main;block=end]

Thanks
mpol_ch
By: M. Polat
Date: 2014-10-07
Time: 12:14

Re: MySQL->DOCX block with repeating records

Hello
I solved my problem with above code. I have now only one question regarding to "Page Break". I am entered in docx template "CRTL+Enter" before [main;block=end].  It works but now I have always a empty page at the end of document.
Where/What should I insert to get the same result with no empty page at the end of document?

Thanks
mpol_ch
By: Skrol29
Date: 2014-10-07
Time: 17:24

Re: MySQL->DOCX block with repeating records

Hi M. Polat,

When you enter [CRTL]+[Enter] then Ms Word insert a page break nested into an invisible paragraph.
So you can delete the last page including the last page break by adding a TBS tag after you [main;block=end]:
[onshow;when 0=1;block=tbs:p:+(tbs:p)]
This mean: the previous paragraph + paragraph nesting the current tag

Another smart solution is to :
1) replace both [main;block=begin] and [main;block=end] with [main;block=tbs:page]
2) delete your last page-break
3) at the very first paragraph of the first page, set the option "page break before" to checked at the paragraph properties.
By: M. Polat
Date: 2014-10-07
Time: 20:21

Re: MySQL->DOCX block with repeating records

Hello
Thank a lot for your advice. But I did not succed with both variations for the page break. I replaced th main blocl with your suggestion but than the creation of document is to slow.
Maybe I am doing a mistake. It will be very kind if you could do the changes previous message on the docv template. So I can avoid any mistake that I am doing. Anyway it works for me. In worst case I can live with a additional empty page too.
thanks.
M. Polat