0

Environment: PHP 5.3.5 MySQL Server 5.5.8

Was Using TBS 3.7.0 Now Using TBS 3.8.2

In the sql dataset that I merged to TBS (TinyButStrong) I have a sender / recipient info. I want to display the one that is currently not user. I am having trouble getting the TBS IF THEN statements working.

IN php

$user_id = getUserId(); // returns user id
...
$TBS->MergeBlock('activity',$sql_data);

IN html, the first name is not being populated, while the last name is cause I am just directly requesting the value, even though it maybe the incorrect value.

<li>
   <div id="name">
     <a href="">
        [
         if [activity.sender_id]!=[var.user_id];
           then[activity.sender_firstname];
         else[activity.recipient_firstname];
           block=li;headergrp=message_id;ope=max:12
        ]
        [activity.sender_lastname;block=li;headergrp=message_id;ope=max:12]
      </a>
    </div> 
</li>

I have been searching and reading the TBS manual but the examples of using if / else with blocks are not like this.

Could someone please help show me what it is I am doing incorrectly?

Currently my output looks like this:

[if1!=2;then Joe;else Jane;block=li;headergrp=message_id;ope=max:12] Doe

When I just want the output to be Jane.

mcv
  • 1,380
  • 3
  • 16
  • 41

2 Answers2

0

You need a tag to indicate when you want to evaluate the if statement or it will never evaluate, only fill in the variables (this is why you get that output). Try:

[onshow; 
     if [activity.sender_id]!=[var.user_id];
       then[activity.sender_firstname];
     else[activity.recipient_firstname];
       block=li;headergrp=message_id;ope=max:12
    ]
Sarah Kemp
  • 2,670
  • 3
  • 21
  • 29
  • by adding that onshow; I have no output. The div which displayed multiple records now is empty. And Yes I already made a call to $TBS->Show(); – mcv Jan 10 '14 at 16:12
  • Same applies for onload; – mcv Jan 10 '14 at 16:22
  • Upgraded my TBS it doesn't disappear it just adds onload; or onshow; to the output above now. Any more ideas? – mcv Jan 10 '14 at 17:08
  • Try using your block perhaps `[activity;block=li;if...else...]` – Sarah Kemp Jan 10 '14 at 17:24
  • Thanks. I might consider that later but I just did a data clean up before I merge the data, much easier than beating my head against the desk. – mcv Jan 10 '14 at 18:27
0

You can use parameter "if" alone in order to hide the value when the condition is not true.

<li>
   <div id="name">
     <a href="">
        [activity.sender_firstname;if [var.user_id]!=[activity.sender_id]]
        [activity.recipient_firstname;if [var.user_id]==[activity.sender_id]]
        [activity.sender_lastname;block=li;headergrp=message_id;ope=max:12]
      </a>
    </div> 
</li>

There is also a solution with conditional sections, but they don't work with parameter "headergrp".

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • I'll attempt this later but I filtered the data prior to processing the html and removed these conditional statements. – mcv Jan 13 '14 at 18:10
  • You're rigth, it is better to prepare the data at the PHP side. – Skrol29 Jan 15 '14 at 13:35