Categories > TinyButStrong general >

alternate text when no sub-block on dynamic query

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TomH
Date: 2011-11-07
Time: 22:02

alternate text when no sub-block on dynamic query

I am trying to show alternate text when there is no sub block for a dynamic query
my php
    $Db->SetTbsKey('mfgs_reps');
   
    $TBS->MergeBlock('main', 'mfgs_reps', 'SELECT mfg_id,name,specialty,website,city,state FROM mfgs WHERE name LIKE \'%'.$mfr_name.'%\' ORDER BY name');
    $insert_flag="";
    $result_flag = "yes"; // hide the descriptive text insert after form submitted
   
    // test if we have any reps (( because I'm not smart enough to do flag using 'sub' result ))
    $sub_result_flag = "yes"; // hide the descriptive text insert after form submitted
    if(!$rep_result=$Db->GetRows($queryreps)){
        $sub_result_flag="";
    }
   
    $TBS->MergeBlock('sub', 'mfgs_reps', 'SELECT * FROM reps,mfgs_reps WHERE (mfg_id = %p1%) and reps.rep_id = mfgs_reps.rep_id ORDER BY reps.rep_id');

my template
            <table  width="500" border=0 style="margin-left:0px;">
            <tr>
            <td  colspan=2  style="padding-bottom:10px;">
            <a href="http://[main.website;magnet=a;mtype=m+m;]" target="_reps">[main.name;block=tr;htmlconv=no;]</a>
             &#160; <field>[main.city;magnet=field;noerr;]</field> <field>  &#160; [main.state;magnet=field;noerr;]</field>

           
            <table width=500>
            <tr>
            <td width=10>&#160;</td>   
            <td width=140 >
            <a href="http://[sub.website;magnet=a;noerr;]">[sub.name;block=tr;p1=[main.mfg_id];magnet=tr;ifempty='No Reps listed';]</a>
            </td>
            <td width=360 >
             &#160; <field>[sub.city;magnet=field;noerr;]</field> <field>  &#160; [sub.state;magnet=field;noerr;]</field>
            <field>[sub.phone;magnet=field;noerr;]</field>
            <field><br /></field>
            <field></field>
            </td>
            </tr>
            <tr>
            <th colspan=3 align=center>  [var.sub_result_flag;ifempty='No Reps listed';noerr;] </th>
            </tr>

            </table>
           
            </td>
            </tr>
           
            <td colspan=2 align=right style="padding-bottom:10px;"><hr>
            </td>
            </tr>
            </table>


The results look like this
---------------------------------------------------------------------

HydroWorx International, Inc.   Middleton   PA
No Reps listed

Hydrozo (Enviroseal) / BASF Building Systems   Shakopee   MN
      Brendon Garvin       Charlestown   MA 617-242-2525
      Ed Senger       Blue Bell   PA 610-279-2003
      Scott Suttinger       Belchertown   MA 413-283-4733
No Reps listed

Riverside Hydronics   Forth Worth   TX
      Robert F. Smith, Jr.       Auburn   NH 603-644-5554
No Reps listed

Zurn Industries, Inc. (Hydromechanics / Plumbing Div.)   Erie   PA
            Woburn   MA 781-933-0436
            781-933-0436
No Reps listed
-----------------------------------------------------------------------

Can anyone see what's wrong? Or see a simpler way to do this?

Thanks for TBS every day,
TomH

By: Skrol29
Date: 2011-11-07
Time: 23:56

Re: alternate text when no sub-block on dynamic query

Hi TomH,

You should replace
<th colspan=3 align=center>  [var.sub_result_flag;ifempty='No Reps listed';noerr;] </th>
with:
<th colspan=3 align=center>  [sub;block=tr;nodata]No Reps listed </th>

The "nodata" section of a block is displayed instead of noting when the block has no data...
By: TomH
Date: 2011-11-08
Time: 00:14

Re: alternate text when no sub-block on dynamic query

Skrol,

Thank you - immediate success!  And.. thanks for not doing RTFM on me ;)

So much to learn - but every day it is more clear that there is nothing to compare to TBS (and now TbsSQL)

Thanks for TBS every day, even your 'betas' are better than all the others,
TomH