Categories > TinyButStrong general >

Problem while merging a 2D array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jeff
Date: 2006-01-11
Time: 15:50

Problem while merging a 2D array

Hi Skrol29,

First of all I would like to thank you for this nice piece of code that turn our lifes easier while using it! I have been using it for about 6 months and I am really enjoying it. But I am having some troubles when trying to merge a bi-dimensional array (matrix).

I have followed the example where you show the "Dynamic columns" because I thought it would be the closest one that would be applied to my problem. But I am just getting one row (the first row only) being showed in the HTML as result.

Here is the code:

HTML:
  <table width="100%" height="100%" border="1" cellpadding="1" cellspacing="0">
    <tr>
      <td bgcolor="DDDDDD" colspan="31"><b>Days</b></td>
    </tr>
    <tr>
      <td bgcolor="DDDDDD">[c0.key;block=td]</td>
    </tr>
    <tr>
      <td>[r.[c1.val;block=td];frm='hh:nn']</td>
    </tr>
    <tr><td colspan="31">&nbsp;</td></tr>
  </table>

PHP:
    public function generateReportCheckPointVisit()
    {
        $conn = DBConnection::returnInstance();
        $conn->setDatabase("test");
        $TBS = new clsTinyButStrong();
        $TBS->LoadTemplate('itf/Alpha/pages/mapaframe.htm');
        $dh = new DateHour(null,null,null,01,01,2005);
       
        $dates = array();
        for($col=1;$col<=$dh->lastDayOfMonth();$col++)
            $dates[$col] = 'column_'.$col;
       
        $data = array();
        $rs = $conn->runQuery("SELECT DISTINCT starthour,endhour,buttoncode FROM Buttons INNER JOIN PatrolsCheckPoints ON buttoncode = Buttons_buttoncode INNER JOIN PatrolsCheckPoints_has_PatrolsCircuits ON Buttons_buttoncode = PatrolsCheckPoints_Buttons_buttoncode INNER JOIN PatrolsCircuits ON PatrolsCircuits_circuitcode = circuitcode  WHERE visitdate >= '2005-01-01' AND visitdate <= '2005-01-31' ORDER BY starthour");
        $row = 1;
        while(!$rs->EOF)
        {
            if($rs->fields["starthour"]>="23:00:00")
                $query = "SELECT visitdate,visithour,buttoncode FROM Buttons INNER JOIN PatrolsCheckPoints ON buttoncode = Buttons_buttoncode INNER JOIN PatrolsCheckPoints_has_PatrolsCircuits ON Buttons_buttoncode = PatrolsCheckPoints_Buttons_buttoncode INNER JOIN PatrolsCircuits ON PatrolsCircuits_circuitcode = circuitcode  WHERE visitdate >= '2005-01-01' AND visitdate <= '2005-01-31' AND visithour >= '".$rs->fields["starthour"]."' AND buttoncode = '".$rs->fields["buttoncode"]."' ORDER BY visitdate,visithour";
            else
                $query = "SELECT visitdate,visithour,buttoncode FROM Buttons INNER JOIN PatrolsCheckPoints ON buttoncode = Buttons_buttoncode INNER JOIN PatrolsCheckPoints_has_PatrolsCircuits ON Buttons_buttoncode = PatrolsCheckPoints_Buttons_buttoncode INNER JOIN PatrolsCircuits ON PatrolsCircuits_circuitcode = circuitcode  WHERE visitdate >= '2005-01-01' AND visitdate <= '2005-01-31' AND visithour >= '".$rs->fields["starthour"]."' AND visithour < '".$rs->fields["endhour"]."' AND buttoncode = '".$rs->fields["buttoncode"]."' ORDER BY visitdate,visithour";
            $rs2 = $conn->runQuery($query);
            $data_col = array();
            $col = 1;
            while(!$rs2->EOF)
            {
                $i = explode("-",$rs2->fields["visitdate"]);
                $data_col[$dates[$i[2]]] = $rs2->fields["visithour"];
                $rs2->MoveNext();
                $col++;
            }
            $data[$row] = $data_col;
            $data_col = null;
            $row++;
            $rs->MoveNext();
        }
        for($i=1;$i<=count($data);$i++)
        {
            for($j=1;$j<=31;$j++)
            {
                if($data[$i]["column_".$j]=='' || $data[$i]["column_".$j]==null)
                    $data[$i]["column_".$j] = "";
            }
            ksort($data[$i]);
        }
        $TBS->MergeBlock('c0,c1',$dates);
        $TBS->MergeBlock('r',$data);
        $TBS->Show();
    }

The idea of this code is to take the result from the query that is run at $rs2, take this result and sort it at the $data array and I must show the data of this array in the HTML (I am using the ADODB library together with the tbsdb_jladodb.php to be able to work with ADODB+TBS). If you pay attention both PHP and HTML codes are very similar to the "Dynamic columns" example.
This shouldn't produce all the rows? It is just showing the first one. I have been debugging the code trying to find the problem but I just didn't. This code should't produce something like this:
   1       2       3      4      5
1 data  data data
2                data   data  data
.
.
.

But it is just producing this:
   1       2       3
1 data  data data

Thanks for the space and the opportunity!
Jeff.
By: Skrol29
Date: 2006-01-11
Time: 16:34

Re: Problem while merging a 2D array

Hello,

This is probably because tag [r.[c1.val;block=td];frm='hh:nn']
doesn't have "block=tr".

When a block hasn't a bound definition, TBS merges only the first record.
By: Jeff
Date: 2006-01-12
Time: 12:56

Re: Problem while merging a 2D array

Hi Skrol,

Thanks for your attention. I have changed [r.[c1.val;block=td];frm='hh:nn'] to [r.[c1.val;block=tr];frm='hh:nn'] but then instead of printing by row it is printing by column and still printing just one row/column from the array. I have tried changing to [r.[c1.val;block=td];frm='hh:nn';block=tr] but I had no changes/result.

I had just followed the example that show the "Dynamic columns" and the block is defined as td as well in the HTML. Both codes are very similar.

I am using PHP 5.0.5 with TBS 2.05.5.

Is there any other way for printing 2D arrays/matrix using the TBS?

Thank you very much for your attention!
By: Skrol29
Date: 2006-01-12
Time: 18:08

Re: Problem while merging a 2D array

Could you send to me a var_export() of $dates and $data, so I can reproduce your snippet in local?
By: Jeff
Date: 2006-01-23
Time: 14:27

Re: Problem while merging a 2D array

Hi Skrol,

I had already sorted it out! I guess my fail was because I think I didn't had updated the HTML file in the server I was using.
The problem was sorted using [r.[c1.val;block=td];frm='hh:nn';block=tr].

Thank you very much for your help!