Categories > TinyButStrong general >

Absolutely Newbie

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: alkaest2002
Date: 2006-11-02
Time: 17:25

Absolutely Newbie

Hi everybody. I started using TbS and I am trying to solve this problem.

I have a block field with ondata parameter set to a function (d1)

the function is as follows:


function d1($BlockName,&$CurrRec,$RecNum) {
                global $class;
                $class="odd";
                if ($RecNum % 2 == 0) {
                    $class = "even";
                }
            }


Unfortunately, $RecNum always equals the number of rows of the query rather than the number of the row that is being processed.
Say, for example, that I have 4 records; than $RecNum is always 4. But I expected it to be 1,2,3,4. Am I wrong? I would be very grateful if anyone could help me with this issue.
By: Skrol29
Date: 2006-11-02
Time: 19:09

Re: Absolutely Newbie

Hi,

This is strange. It should be 1,2,3,...
Is your data source a PHP array or another source ?
By: alkaest2002
Date: 2006-11-03
Time: 06:48

Re: Absolutely Newbie

Dear Skrol29, thank you for the quick reply. I am getting the data
from mysql trough ezsql class.
In the html template I have the following code:


<table>
        <tr class='[var.class]'>
            <td>[bl1.id;block=tr;ondata=d1]</td>
            <td>[bl1.name]</td>
            <td>[bl1.email]</td>
            <td>[bl1.age]</td>
            <td>[bl1.country]</td>
        </tr>
    </table>


The php file contains (apart from includes):


$db = new ezSQL_mysql();
$data = $db->get_results("SELECT id,name,email,age,country FROM example",ARRAY_A);
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('template.html');
$TBS->MergeBlock('bl1',$data);
$TBS->Render=TBS_OUTPUT;
$TBS->Show();
       
function d1($BlockName,&$CurrRec,$RecNum) {
global $class;
$class="odd";
if ($RecNum % 2 == 0) {
      $class = "even";
    }
}


With this code I am getting the total number of rows via $RecNum.
By: Skrol29
Date: 2006-11-04
Time: 00:08

Re: Absolutely Newbie

What is your TBS version ?
Are you using PHP 4.4.1 (ther is a bad bug with it) ?
If not, what is your PHP version ?
By: Skrol29
Date: 2006-11-04
Time: 00:24

Re: Absolutely Newbie

Hi alkaest2002,

I've tested your snippet and row number are rendered correctly.
How do you know that $RecNum is always 4 ?

By the way, your code cannot make the <tr> class to be alternatively "odd" and "even". This is because [var] fields are merged all together at the end of the merge. The the golden rules for more details about this.

To alternate the rows, you can simply use two sections instead of one (see examples in line for that)
By: alkaest2002
Date: 2006-11-05
Time: 17:12

Re: Absolutely Newbie

Dear Skroll29,
thank you for your advices. I think I found a solution by adding a new field (containing the class specification) to $CurrentRecord in the function (just to overcome the var merging issue). In the template I changed the var field to a normal field.
Basically, my intention is to adhere to CSS formatting rules, that is why I didn't follow the TBS classical way of making presentational formatting of different rows.
I would be very interested to know your opinion about that.
By the way, TBS is an excellent tool and I am glad to use it. Cheers!