Categories > TinyButStrong general >

P1

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Mike
Date: 2004-05-20
Time: 01:32

P1

Hello,

I've been trying to use the %P1% exactly like on the manual webpages but for some reason it doesn't resolve.
Is there an automated way to determine whether you need
'%p1%' => when the value is a string or
%p1 => when the value is an integer.

However when I use %p1% I get a mysql error of the query being not understood. (Although the value is an integer). When I use '%p1%', there are no complaints but it cannot find the value (as you are comparing a string with an integer).

Am I doing something wrong?

Examples taken from the manual:
Stringbased P1
$TBS->MergeBlock('blk',$cnx_id,"SELECT town,country FROM t_geo WHERE (country='%p1%')")

Integerbased P1
$TBS->MergeBlock('main',$cnx_id,'SELECT country,cntr_id FROM t_country')
$TBS->MergeBlock('sub',$cnx_id,'SELECT town FROM t_town WHERE (cntr_id=%p1%)')
By: Skrol29
Date: 2004-05-20
Time: 11:38

Re: P1

Hi Mike,

No, there is no automated way that determines whether you need '%p1%' or %p1%. The keyword is %p1% alone, and should be string protected or not in the SQL statement depending to the field type.

Your proplem is probably that you didn't define the parameter p1 in the block, so TBS hasn't activated the sub-block feature.
Then SQL doesn't understand "(cntr_id=%p1%)" but understand "(cntr_id='%p1%')" because the keyword is not replaced by its value.
By: Mike
Date: 2004-05-21
Time: 03:30

Re: P1

Makes sense that I didn't activate something.
Here is the code I use, maybe it is obvious, but I cannot find a full example of the usage of P1 so my apologies:
HTML Template:
    [main.category_name;block=table]
    [sub.name;block=opt;p1=main.category]

PHP Script:
include_once('tbs_class.php');
require('admin/Bookmark.db.php');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('table-template-tbs.html') ;
$TBS->MergeBlock('main',$cnx_id,'SELECT category,category_name FROM `bookmarks-categories`');
$TBS->MergeBlock('sub',$cnx_id,'SELECT name FROM bookmarks WHERE (category=%p1%)') ;
mysql_close($cnx_id) ;
$TBS->Show() ;

I don't know where to put the P1 declaration...
BTW. I love your product! :-)

Mike
By: Skrol29
Date: 2004-05-21
Time: 03:40

Re: P1

HTML part should be :
[main.category_name;block=table]
[sub.name;block=opt;p1=[main.category]]

In your current version, "p1=main.category" is not merged, and parameter p1 has always the string value "main.category".
By: Mike
Date: 2004-05-21
Time: 09:32

Re: P1

I tried that, but still get the same message:
TinyButStrong Error (MergeBlock Method): MySql: 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

Photos 1
[sub.name;block=opt;p1=1]
By: Skrol29
Date: 2004-05-21
Time: 12:14

Re: P1

TBS behaves like parameter p1 is not taken in acount.
Can you check that there is no [sub.*] tags with a block definition before the [sub.name;block=opt;...] tag ?

If there is not, could you send or post a larger part of your template?