Categories > [old] TbsOoo & TinyDoc >

nested queries with page breaks

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: sam
Date: 2006-02-03
Time: 11:26

nested queries with page breaks

I have a mysql table with 5 school classes (there are lots more but I've simplified for this explanation)  each with different number of students in each class.
e.g
class 1  has 15 students (fname,surname)
class 2  has 18 students (fname,surname)
class 3  has 22 students (fname,surname)
class 4  has 17 students (fname,surname)
class 5  has 20 students (fname,surname)

I'd like to merge them and put each class on a seperate page.
ie:
page 1 has class1 with a table of 15 rows down it
page 2 has class2 with a table of 18 rows down it
page 3 has class3 with a table of 22 rows down it
page 4 has class4 with a table of 17 rows down it
page 5 has class5 with a table of 20 rows down it

ie a 5 page openoffice doc.

I've tried using sublocks but still only get the one page (+1 page break as well=2page doc)

[data;block=begin]

[data2;block=begin]
[data2.fname] [data2.surname]
[data2;block=end]

PAGE-BREAK
[data;block=end]

The main code in the php file is:
$sql1="select distinct(class) from table";
$sql2="select fname,surname from table";

$OOo->MergeBlock('data',$connection,$sql1) ;
$OOo->MergeBlock('data2',$connection,$sql2) ;

Any help would be appreciated
sam
By: sam
Date: 2006-02-08
Time: 06:51

Solved but too slow Re: nested queries with page breaks

Solved... but too slow!
I managed to hack one of the example scripts but I have found that it runs too slow.
Firstly here is the scenario:
I have a mysql table with about 6000 records in the format (some fileds included as example)
ID,surname,name,Year,class,Line,Tea_title,Tea_GN,Tea_SN
00.157,Nyland,Garron,12,12ComFSLC,3,Mrs,Deborah,Barth
00.157,Nyland,Garron,12,12InfPrLF,6,Ms,Lorr,Hughes
00.157,Nyland,Garron,12,12Math3LB,2,Mrs,Linette,McEndy
00.157,Nyland,Garron,12,12Soc/CLD,4,Mr,Paulya,Turley
01.007,Valencius,Tara,12,12DramaLC,3,Mrs,Katy,Walcolm
01.007,Valencius,Tara,12,12EngA1LA,1,Mrs,Edie,Wronda
01.007,Valencius,Tara,12,12Hosp1LF,6,Mrs.,Annette,Tungston
01.007,Valencius,Tara,12,12Math3LB,2,Mrs,Linette,,McEndy
01.008,Hudson,Jacob,12,12BusStLC,3,Mr,Gerard,Walsh
01.008,Hudson,Jacob,12,12EconLF,6,Mr,Malcolm,Finstool

Now from this I need to make a classlist an put these on a unique page. So I populate an array classes[] with this (theres only about 65 classes) then I loop through each of the classes using the hacked subblock example and produce a class list on each page. It works but is too slow. I have to increase the timeout of querying mysql to be about 3 mins - which is way too slow, before the openoffice document is produced.
Here is my codeing:
FIrst the openoffice file looks like (download it from my server:

the phpcode is as follows:
<?php
include_once('../tbs_class.php');
include_once('../tbsooo_class.php');
include_once('../../common.php');


$sql="SELECT *,count(class) as classtots FROM rec6000 where Year = '11' group by class order by Line,class";
//$sql="select r.*,s.* from rec6000 as r left join 800lines as s on r.ID=s.ID where r.class='12InfPr LC'";
$result= mysql_query ($sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$i==0;

// send a blank one on page 1:
$classes[] = array('classname'=>"" ,'total'=>'','no'=>'');

while($row = mysql_fetch_array($result))

    $numinclass=$row[classtots]-1;
    if ($numinclass > 0) {
        $i++;
        $classes[] = array('classname'=>"$row[class]" ,'total'=>$numinclass,'no'=>$i);
    }

}
// ????????????????????????????????????????????????????????????????????
// #########################################################################3



    reset($classes);
//print_r($classes);

$j==0;
while (list($key,$val) = each($classes)) {

   
    $subj=$classes[$key][classname] ;

    $sql2="SELECT * from rec6000 where class='$subj'";
    $result= mysql_query ($sql2);
    $row = mysql_fetch_array($result,MYSQL_ASSOC);

    while($row = mysql_fetch_array($result))
    { 
        $TeamListy[$j]['matches'][] =  array('town'=>"$row[name]",'score'=>"$row[surname]");   

    }
    $j++;
}

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



// instantiate a TBS OOo class
$OOo = new clsTinyButStrongOOo;

// setting the object
$OOo->SetZipBinary('zip');
$OOo->SetUnzipBinary('unzip');
$OOo->SetProcessDir('./tmp');

// create a new openoffice document from the template with an unique id
$OOo->NewDocFromTpl('subblock_nsheets.odt');

// merge data with openoffice file named 'content.xml'
$OOo->LoadXmlFromDoc('content.xml');

$OOo->MergeBlock('mb','array','classes') ;
$OOo->MergeBlock('sb','array','TeamListy[%p1%][matches]') ;


$OOo->SaveXmlToDoc();

// display
header('Content-type: '.$OOo->GetMimetypeDoc());
header('Content-Length: '.filesize($OOo->GetPathnameDoc()));
$OOo->FlushDoc();
$OOo->RemoveDoc();
?>

My conclusion is this:
I would love to produce openoffice documents but I need the performance increased. I can at present make them in html in secs then run them throught htmldoc (www.htmldoc.org) to produce a pdf file. OpenOffice is much more preferrable.

Any help would be appreciated
sam