Categories > TinyButStrong general >

Conditional Block problem

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TREVOR
Date: 2009-09-13
Time: 20:02

Conditional Block problem

Dear Skrol29 and TBS brainiacs,
Very pleased with the way TBS gets my website displayed so far. (www.handsel.com).
My next improvement is to display "out of stock" or "discontinued" instead of my buy button when I put a value of "O" or "D" in a field called in_stock. This in_stock field would otherwise not have a value (Or I could populate it with "I" or "1" if I had to.)

I have adapted your TBS conditional block example as shown below - but it does not work. Please can someone spot where I have gone wrong ....I have spent all afternoon trying quite a few variations - and I cannot crack it...I am sure it is just down to my lack of programming experience.

Best wishes.....Trevor

<table class="block" border="1" style="text-align:center" cellpadding="2" cellspacing="0">
 
    <tr>
    [blk.description;block=tr;when[blk.in_stock]="O"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.sales_price;frm='£000.00']<br />[blk.detail]<br />OUT OF STOCK - SORRY!</tr>

    <tr>
    [blk.description;block=tr;when[blk.in_stock]="D"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.sales_price;frm='£000.00']<br />[blk.detail]<br />DISCONTINUED - SORRY!</tr>

    <tr>
    [blk.description;block=tr;default]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.sales_price;frm='£000.00']<br />[blk.detail]<br />

    <a href="http://ww9.aitsafe.com/cf/add.cfm?userid=B059001&amp;product=[blk.stock_code]++[blk.description2]&amp;price=[blk.sales_price]&amp;units=[blk.units]&amp;qty=[blk.qty]&amp;return=http://ccgi.handsel.plus.com/alpha/sil0308/sleep/s_sleep.php%23h[blk.id]">
        <img id="img[blk.id]" src="../../buttonB1.gif" height="15" width="50" alt="BUY ME" onmouseover="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" onmouseout="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB1.gif')" onmousedown="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB3.gif')" onmouseup="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" style="border:0px none" title="BUY ME" /></a></tr>

  <tr style="background-color:#E6E6E6">
    <td  >[blk;block=tr;nodata]There is no data. </td>
  </tr>
</table>
By: TomH
Date: 2009-09-13
Time: 21:32

Re: Conditional Block problem

Hi

A few things...

* what result are you getting? (show html source please)

* test to confirm what val TBS is getting for blk.in_stock by displaying it in the page

* any error messages?

Thanks,
By: TREVOR
Date: 2009-09-13
Time: 23:06

Re: Conditional Block problem

Thank you for your quick response TomH.

I have simplified my test code so there is just "description","stock_code" and "in_stock" in each section - as immediately below.

  <table class="block" border="1" style="text-align:center" cellpadding="2" cellspacing="0">
 
    <tr>
    [blk.description;block=tr;when[blk.in_stock]="O"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />OUT OF STOCK - SORRY!</tr>

    <tr>
    [blk.description;block=tr;when[blk.in_stock]="D"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />DISCONTINUED - SORRY!</tr>

    <tr>
    [blk.description;block=tr;default]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />

    <a href="http://ww9.aitsafe.com/cf/add.cfm?userid=B059001&amp;product=[blk.stock_code]++[blk.description2]&amp;price=[blk.sales_price]&amp;units=[blk.units]&amp;qty=[blk.qty]&amp;return=http://ccgi.handsel.plus.com/alpha/sil0308/sleep/s_sleep.php%23h[blk.id]">
        <img id="img[blk.id]" src="../../buttonB1.gif" height="15" width="50" alt="BUY ME" onmouseover="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" onmouseout="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB1.gif')" onmousedown="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB3.gif')" onmouseup="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" style="border:0px none" title="BUY ME" /></a></tr>

  <tr style="background-color:#E6E6E6">
    <td  >[blk;block=tr;nodata]There is no data. </td>
  </tr>
</table>

The following is html source code - the first 5 records have nothing in the in_stock field. Record 6 has "O". Record 7 has "D". No other records have anything in the in_stock field.
There are no error messages.

<table class="block" border="1" style="text-align:center" cellpadding="2" cellspacing="0">
 
    <tr>
    SILVER SLEEPER<br />
    SE400C/08&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</tr><tr>
    SILVER SLEEPER<br />

    SE400C/10&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</tr><tr>
    SILVER SLEEPER<br />
    SE400C/12&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</tr><tr>
    SILVER SLEEPER<br />
    SE400C/14&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</tr><tr>

    SILVER SLEEPER<br />
    SE400C/16&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</tr><tr>
    SILVER SLEEPER<br />
    SE401/10&nbsp;&nbsp;O<br />DISCONTINUED - SORRY!</tr><tr>
    SILVER SLEEPER<br />

    SE401/12&nbsp;&nbsp;D<br />OUT OF STOCK - SORRY!</tr><tr>
    SILVER SLEEPER<br />
    SE401/16&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</tr><tr>
    SILVER SLEEPER<br />
    SE401/18&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</tr><tr>
    SILVER SLEEPER<br />

    SE402/24&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</tr>

I am sure I am making some very basic mistake - but I just cannot see it.
Best wishes....Trevor
By: TomH
Date: 2009-09-14
Time: 01:31

Re: Conditional Block problem

My point was that you need to show the value of blk.instock in the html output to be able to verify that you are in fact cycling through the db records in the way expected. Also, use proper html struct by using td tags inside tr tags.
Example...
<tr>
<td>
    [blk.description;block=tr;when[blk.in_stock]="O"]
    - (instock = [blk.instock])<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />OUT OF STOCK - SORRY!
</td>
</tr>

By: TomH
Date: 2009-09-14
Time: 01:41

Re: Conditional Block problem

Sorry for that last post, obvious brain fade on my part :(
By: TREVOR
Date: 2009-09-14
Time: 10:00

Re: Conditional Block problem

Thank you - it does need the <td> tags for the blocks to show correctly - which they now do. 

  <table class="block" border="1" style="text-align:center" cellpadding="2" cellspacing="0">

<tr><td>
    [blk.description;block=tr;when[blk.in_stock]="O"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />OUT OF STOCK - SORRY!</td></tr>

<tr><td>
    [blk.description;block=tr;when[blk.in_stock]="D"]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />DISCONTINUED - SORRY!</td></tr>

<tr><td>
    [blk.description;block=tr;default]<br />
    [blk.stock_code]&nbsp;&nbsp;[blk.in_stock]<br />

    <a href="http://ww9.aitsafe.com/cf/add.cfm?userid=B059001&amp;product=[blk.stock_code]++[blk.description2]&amp;price=[blk.sales_price]&amp;units=[blk.units]&amp;qty=[blk.qty]&amp;return=http://ccgi.handsel.plus.com/alpha/sil0308/sleep/s_sleep.php%23h[blk.id]">
  <img id="img[blk.id]" src="../../buttonB1.gif" height="15" width="50" alt="BUY ME" onmouseover="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" onmouseout="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB1.gif')" onmousedown="swapImg(1,0,/*id*/'img[blk.id]',/*url*/'../../buttonB3.gif')" onmouseup="swapImg(0,0,/*id*/'img[blk.id]',/*url*/'../../buttonB2.gif')" style="border:0px none" title="BUY ME" /></a></td></tr>

  <tr style="background-color:#E6E6E6">
    <td  >[blk;block=tr;nodata]There is no data. </td>
  </tr>
</table>

- and it is picking up each record in turn as it should do, but it uses each of the top two options alternatively!
It should be using the third option every time until it reaches record 6 (which should show "Out of Stock") and record 7 (which should show "Discontinued").

<table class="block" border="1" style="text-align:center" cellpadding="2" cellspacing="0">

<tr><td>
    SILVER SLEEPER<br />
    SE400C/08&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE400C/10&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE400C/12&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE400C/14&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE400C/16&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE401/10&nbsp;&nbsp;O<br />DISCONTINUED - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE401/12&nbsp;&nbsp;D<br />OUT OF STOCK - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE401/16&nbsp;&nbsp;<br />DISCONTINUED - SORRY!</td></tr><tr><td>
    SILVER SLEEPER<br />
    SE401/18&nbsp;&nbsp;<br />OUT OF STOCK - SORRY!</td></tr><tr>

Sorry - I am still baffled - Best wishes...Trevor
By: Pirjo Posio
Date: 2009-09-14
Time: 17:17

Re: Conditional Block problem

Hi Trevor,

I noticed one problem in your code, but it may not be all that is needed to solve it:
You have no space between "when" and the TBS tag. Check the examples for "Conditional Blocks" if needed.

Pirjo
By: TREVOR
Date: 2009-09-14
Time: 18:13

Re: Conditional Block problem

Brilliant! Well spotted Pirjo.

The space between "when" and the TBS tag gets the default option working.

I then changed "O" and "D" into 'O' and 'D' to get it all working properly.

Thank you very much - I am afraid I do not do enough coding to be able to pick up some of these important details myself. I greatly appreciate the help I am given on this forum.

Best wishes.....Trevor
By: tonier
Date: 2009-09-15
Time: 04:20

Re: Conditional Block problem

That is really a weird solution, but it's work :)

thanks and my ancient and weird bug code fixed now (>,<)