Categories > TinyButStrong general >

What's wrong? Dynamic sub-blocks

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: magictrickpony
Date: 2004-06-30
Time: 13:44

What's wrong? Dynamic sub-blocks

Hi!

Another problem on my part. I am trying to use dynamic sub blocks with a postgres database and it just does not seem to work the way i intend to, tbs' behaviour is very irritating.

<?
// Hooray for sub blocks???

include_once('tbs_class.php');

$cnx_id = pg_connect("host=localhost port=5432 dbname=mydb user=postgres password=secret);

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('template_infra.html') ;
$TBS->MergeBlock('blk1',$cnx_id,'SELECT * FROM t_circuit ORDER BY id limit 50');
$TBS->MergeBlock('blk2',$cnx_id,'SELECT * FROM location WHERE (idx=\'%p1%\') ORDER by idx');
$TBS->MergeBlock('blk3',$cnx_id,'SELECT * FROM location WHERE (idx=\'%p2%\') ORDER by idx');
$TBS->MergeBlock('blk4',$cnx_id,'SELECT * FROM t_bill WHERE (circuitkey=\'%p3%\') ORDER by id');
pg_close($cnx_id) ;
$TBS->Show() ;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<table border="1" align="center" cellpadding="2" cellspacing="0">
  <tr>
   <td>[blk1.pcircuitid;block=tr]</td>
    <td>[blk1.pname]</td>
     <td>[blk1.service]</td>
      <td>[blk1.bw]</td>
      </tr><tr>
   <td>[blk2.name;block=tr;p1=[blk1.a_end]]</td>
    <td>[blk2.address]</td>
     <td>[blk2.pcode]</td>
      <td>[blk2.city]</td>
       <td>[blk2.country]</td>
       </tr><tr>
   <td>[blk3.name;block=tr;p2=[blk1.b_end]]</td>
    <td>[blk3.address]</td>
     <td>[blk3.pcode]</td>
      <td>[blk3.city]</td>
       <td>[blk3.country]</td>
       </tr><tr>
   <td>[blk4.billstart;block=tr;p3=[blk1.id]]</td>
    <td>[blk4.billend]</td>
     <td>[blk4.charge]</td>
      <td>[blk4.currency]</td>
       <td>[blk4.isreoccuring]</td>
  </tr>
</table>
</html>

I get:

TinyButStrong Error (MergeBlock Method): PostgreeSQL: ERROR: pg_atoi: error in "%p2%": can't parse "%p2%"


TinyButStrong Error (MergeBlock Method): PostgreeSQL: ERROR: pg_atoi: error in "%p3%": can't parse "%p3%"

Well I tried changing the block definitions but got nothing working at least not the way i wanted it to.

--magictrickpony
By: Skrol29
Date: 2004-06-30
Time: 14:09

Re: What's wrong? Dynamic sub-blocks

Hi MagicTrickPony,

Use parameter 'p1' in all your sub-blocks.
And use %p1% in all your queries.

p2, p3, p4... are to be used when you have several parameters in the same sub-block. But here you have 3 different sub-blocks.

Also take care that all your sub-blocks are definied on <tr>.
That will display something strange.
By: magictrickpony
Date: 2004-06-30
Time: 14:19

Re: What's wrong? Dynamic sub-blocks

Salut!

Well, after changing all the p2,p3,p4, etc to p1 I get

TinyButStrong Error (MergeBlock Method): PostgreeSQL: ERROR: pg_atoi: zero-length string

Maybe this has to do with the block statement?

By defined with '<tr>' do you mean inside a table row statement?

--thepony
By: magictrickpony
Date: 2004-06-30
Time: 14:27

Re: What's wrong? Dynamic sub-blocks

Hmm I removed the <tr> statements and now i get only one record to display... (out of a couple hundreds) :-(

Another problem might be that I  have a 1:n relationship..

1 block : n sub-blocks

Example:
mainblock:
<tr>
<td>Patisserie Pierre<td>
</tr>

sub-block:
<tr><td>lundi<td><td>9:00-17:00</td></tr>
<tr><td>mardi</td><td>10:00-18:00</td></tr>

etc

is there any hope left? :-)
By: Skrol29
Date: 2004-06-30
Time: 14:49

Re: What's wrong? Dynamic sub-blocks

If you remove parameter 'block' then MergeBlock() merges only the first record. So what you have is normal.
Whan I meant is that sub-blocks are defined on the same bound that the main block and that others sub-blocks.

What kind of design to you what to have ?
By: magictrickpony
Date: 2004-06-30
Time: 15:09

Re: What's wrong? Dynamic sub-blocks

Well I removed not the block statement but the HTML table row tag <tr>.

<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<link href="form_styles.css" rel="stylesheet" type="text/css">
<table border="1" align="center" cellpadding="2" cellspacing="0">
  <tr bgcolor="#F0F0F0">
   <td>[blk1.pcircuitid;block=tr]</td>
    <td>[blk1.pname]</td>
     <td>[blk1.service]</td>
      <td>[blk1.bw]</td>
   <td>[blk2.name;block=tr;p1=[blk1.a_end]]</td>
    <td>[blk2.address]</td>
     <td>[blk2.pcode]</td>
      <td>[blk2.city]</td>
       <td>[blk2.country]</td>
   <td>[blk3.name;block=tr;p1=[blk1.b_end]]</td>
    <td>[blk3.address]</td>
     <td>[blk3.pcode]</td>
      <td>[blk3.city]</td>
       <td>[blk3.country]</td>
   <td>[blk4.billstart;block=tr;p1=[blk1.id]]</td>
    <td>[blk4.billend]</td>
     <td>[blk4.charge]</td>
      <td>[blk4.currency]</td>
       <td>[blk4.isreoccuring]</td>
  </tr>
</table>
</html>
</code>

This only renders one record.

I want to have the following layout:

<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<link href="form_styles.css" rel="stylesheet" type="text/css">
<table border="1" align="center" cellpadding="2" cellspacing="0">
// THIS IS THE MAIN BLOCK
  <tr bgcolor="#F0F0F0">
   <td>[blk1.pcircuitid;block=tr]</td>
    <td>[blk1.pname]</td>
     <td>[blk1.service]</td>
      <td>[blk1.bw]</td>
</tr>
// FIRST SUB BLOCK in its own row (this gets rendered one time only)
First address:
<tr>
   <td>[blk2.name;block=tr;p1=[blk1.a_end]]</td>
    <td>[blk2.address]</td>
     <td>[blk2.pcode]</td>
      <td>[blk2.city]</td>
       <td>[blk2.country]</td>
</tr>
Second address:
// SECOND SUB BLOCK in its own row (this gets rendered one time only)
<tr>
   <td>[blk3.name;block=tr;p1=[blk1.b_end]]</td>
    <td>[blk3.address]</td>
     <td>[blk3.pcode]</td>
      <td>[blk3.city]</td>
       <td>[blk3.country]</td>
</tr>
// NOW THERE CAN BE N-SUB (n-times) BLOCKS with the following data
// (this can be rendered n-times)
<tr>
   <td>[blk4.billstart;block=tr;p1=[blk1.id]]</td>
    <td>[blk4.billend]</td>
     <td>[blk4.charge]</td>
      <td>[blk4.currency]</td>
       <td>[blk4.isreoccuring]</td>
  </tr>
</table>
</html>
</code>


By: Skrol29
Date: 2004-06-30
Time: 15:35

Re: What's wrong? Dynamic sub-blocks

Ok, if I undersant there should be only 1 blk2 (first address) and blk3 (secondary adress) lines for each blk1 (circuit) line. And then several blk4 (bills) for each blk1 lines.

Like:
Circuit A
  Address A1
  Address A2
  Bills A1
  Bills A2
  Bills A3
  Bills A...
Circuit B
  Address B1
  Address B2
  Bills B1
  Bills B2
  Bills B3
  Bills B...
...

If that is correct, you have to embed the sub-blocks (blk2,blk3,blk4) inside the main block (blk1) :

Exemple :
<table>
  <tr>
     <td>[blk1....;block=tr;extend=4]<td><td>...<td>
  </tr>
  <tr>
     <td>[blk2....;block=tr;p1=...]<td><td>...<td>
  </tr>
  <tr>
     <td>[blk3....;block=tr;p1=...]<td><td>...<td>
  </tr>
  <tr>
     <td>[blk4....;block=tr;p1=...]<td><td>...<td>
  </tr>
</table>

Parameter 'extend' means that the block is not defined on 1 row, but on 4 rows.
By: magictrickpony
Date: 2004-07-01
Time: 09:37

Re: What's wrong? Dynamic sub-blocks

Thanks for the input, but still only the first sub block is rendered correctly.

The second and so on are just being skipped, i.e. not displayed.

I have trimmed the code to find the error, but to no avail

<code>
<html>
<link href="form_styles.css" rel="stylesheet" type="text/css">
<table border="1" align="center" cellpadding="2" cellspacing="0">
  <tr bgcolor="#F0F0F0">
   <td>[blk1.pcircuitid;block=tr;extend=1]</td>
    </tr>
      <tr><td>      <b>[blk2.name;block=tr;p1=[blk1.a_end]]</b><br>[blk2.address]<br>[blk2.pcode] [blk2.city]<br>[blk2.country]
    </td>
      </tr>
</table>
</html>
</code>

All the main blocks are rendered correctly.
The first sub block of the first main block is rendered correctly too, rest are skipped.

<code>
Circuit A
  Address A1
Circuit B
(address skipped)
Circuit C
(address skipped)
Circuit D
(address skipped)
Circuit E
(address skipped)
...
</code>

:-(((
By: magictrickpony
Date: 2004-07-01
Time: 09:42

BUG found: What's wrong? Dynamic sub-blocks

Rut roh!

I tried the whole thing with TinyButStrong version 1.96  and it works!

looks like bug!

just my two cents.. ;-)
By: Skrol29
Date: 2004-07-01
Time: 11:58

Re: What's wrong? Dynamic sub-blocks

I've tested your small template (with blk1 and blk2), with TBS 1.97.7 and the following code:
<?
include_once('tbs_class 1.97.7.php');

//$cnx_id = pg_connect("host=localhost port=5432 dbname=mydb user=postgres password=secret);
$cnx_id = mysql_connect('localhost','root','') ;
mysql_select_db('test',$cnx_id) ;

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('template_infra.html') ;
$TBS->MergeBlock('blk1',$cnx_id,'SELECT * FROM t_circuit ORDER BY id limit 50');
$TBS->MergeBlock('blk2',$cnx_id,'SELECT * FROM location WHERE (idx=\'%p1%\') ORDER by idx');
$TBS->Show() ;
?>

I don't have PosgreSQL, so I've tested with MySQL.
And the result was ok:
Circuit A
  Asdress A1
Circuit B
  Asdress B1
Circuit C
  Asdress C1

Did you have the same PHP code ?
By: magictrickpony
Date: 2004-07-01
Time: 12:38

Re: What's wrong? Dynamic sub-blocks

yes i didn't change anything with the code.

how can i be of further help to debug the problem?
By: Skrol29
Date: 2004-07-01
Time: 15:49

Re: What's wrong? Dynamic sub-blocks

Can you contact me by email ?