Categories > TinyButStrong general >

n number of columns

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: David Christensen
Date: 2004-04-02
Time: 22:57

n number of columns

I cannot seem to figure out how to display a dynamic number of columns.  I tried using a variation of the "serial" format, but I cannot seem to get the table to have a dynamic set of columns.

Is this because the rows are defined first? 

My objective is to have a conditional display that shows either 8, 15, (multiples of 7 there after) columns depending on whatever the user selects from a form input.

Thanks,

Dave C.
By: David Christensen
Date: 2004-04-02
Time: 23:16

Re: n number of columns

Need to add another wrinkle to the problem.  The number of rows is also dynamic.  I could have 2 or more depending on the data returned.

So to put it in DB terms,  the rows are the record sets, and the columns are the fields.  If a user desires more details, the number of columns can grow.  If the user filters the search, the number of rows reduces. 

Thanks again,

Dave C.
By: Skrol29
Date: 2004-04-03
Time: 01:06

Re: n number of columns

Hi,

Someting like this should work:

HTML:
<table width="400" border="1">
  <tr>
    <td width="200">&nbsp;</td>
    <td width="200"><strong>[col_a.val;block=td]</strong></td>
  </tr>
  <tr>
    <td><strong>Record #[rec.#;block=tr] </strong></td>
    <td>[rec.[col_b.val;block=td]]</td>
  </tr>
</table>

We assume that $col_list is an array with the column names, and $recset is an opened recordset ressource.

PHP:
$TBS->MergeBlock('col_a',$col_list);
$TBS->MergeBlock('col_b',$col_list);
$TBS->MergeBlock('rec',$recset);
By: David Christensen
Date: 2004-04-03
Time: 02:23

Re: n number of columns

I should have been more specific in what I was using for data sources.

I'm actually using multi-deminsional arrays to populate the rows:

1st row: $days[] = array('name' => "Monday");
2nd row: $jobs[] = array('name' => $somedata);

The first field in row 1 is blank.  The first field in row2 displays a location associated with the $jobs array.  The "location" is also an array similar to $days[] and fills column 1, starting at row 2.  The $jobs[] array fills column 2 to n, with $somedata.

Thanks for your help,

Dave
By: David Christensen
Date: 2004-04-03
Time: 02:29

Re: n number of columns

Here's an example of what it should look like:

HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>

<body>

<table border="0" width="628" cellspacing="1" height="146">
  <tr>
    <td rowspan="2" bgcolor="#336699" width="30%" align="center" height="56" valign="bottom"><font color="#FFFFFF" face="Arial"><b>Site</b></font></td>
    <td bgcolor="#336699" colspan="7" height="21" width="507" valign="top"><font color="#FFFFFF" face="Arial"><b>Date
      Range: [start] to [end]</b></font></td>
  </tr>
  <tr>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
    <td bgcolor="#333333" width="10%" align="center" height="31"><font color="#FFFFFF" face="Arial"><b>[dow]</b></font></td>
  </tr>
  <tr>
    <td width="30%" height="25" bgcolor="#C0C0C0"><font face="AR Sans Serif">[location]</font></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log0]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log1]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log2]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log3]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log4]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log5]"><font size="1">[job_data</font></a><font size="1">]</font></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log6]"><font size="1">[job_data]</font></a></td>
  </tr>
  <tr>
    <td width="30%" height="25" bgcolor="#C0C0C0"><font face="AR Sans Serif">[location]</font></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log0]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log1]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log2]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log3]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log4]"><font size="1">[job_data]</font></a></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log5]"><font size="1">[job_data</font></a><font size="1">]</font></td>
    <td width="10%" align="center" height="25" bgcolor="#C0C0C0"><a href="file:///G:/public_html/nbu2/nbu/day_view.php?site=[site.name]&log=[site.log6]"><font size="1">[job_data]</font></a></td>
  </tr>
</table>

</body>

</html>
By: Skrol29
Date: 2004-04-03
Time: 02:40

Re: n number of columns

I don't see how you retrieve the job data for a given couple of location+dow (date of work ?)

Hav you the data for all cells?
By: David Christensen
Date: 2004-04-03
Time: 02:44

Re: n number of columns

I've almost got it:

HTML:
<table border="1" align="center" cellpadding="2" cellspacing="0">
  <tr bgcolor="#CACACA">
    <td colspan="4"><div align="center"> Start date / End Date</div></td>
  </tr>

  <tr bgcolor="#F0F0F0">
    <td width="100"><div align="center"><strong>[day.name;htmlconv=no;block=td]</strong></div></td>
  </tr>

  <tr bgcolor="#A0A0A0">
    <td><div align="center"><strong>[sites.name;block=tr]</strong></div></td>
    <td><div align="center"><strong>[job.name;block=td]</strong></div></td>
  </tr>
</table>

PHP:
$TBS->MergeBlock('day',$days);

for ($x=0; $x < count($sites); $x++)
        {
        for ($count = 0; $count < $weeks; $count++)
                {
                $job_info[] = array('name' => "Day[" . $sites[$x]['name'] . "]" . $count);
                }
        $TBS->MergeBlock('job',$job_info);
        }
$TBS->MergeBlock('sites',$sites);
$TBS->Show();
By: David Christensen
Date: 2004-04-03
Time: 02:47

Re: n number of columns

The problem I'm having now is, all the data is for the first locaiton.  So it looks like:

location0   data[location0][0]   data[location0[1]   ...   data[location0[N]
location1   data[location0][0]   data[location0[1]   ...   data[location0[N]
...
locationN   data[location0][0]   data[location0[1]   ...   data[location0[N]

It's not looping the "serial;td" (not right syntax I know) either at the right point, or I'm missising something still.

Thanks again!
By: Skrol29
Date: 2004-04-03
Time: 02:59

Re: n number of columns

You've forgoten to initialize $job_info before the $count loop.

...
$job_info = array();
for ($count = 0; $count < $weeks; $count++)
...
By: David Christensen
Date: 2004-04-03
Time: 03:09

Re: n number of columns

init'ing the $job_info array didn't seem to help.   I'm still getting the same output, which doesn't make sense by the way!

Here's the new PHP code:
#####################################
# Merge the days array (from conf file) into template
###
$temp = array('name' => "&nbsp;");
array_unshift($days, $temp);
$TBS->MergeBlock('day',$days);

for ($x=0; $x < count($sites); $x++)
        {
        $job_info = array();
        for ($count = 0; $count < $weeks; $count++)
                {
                $job_info[] = array('name' => $sites[$x]['name'] . "[Day$count]");
                }

        $TBS->MergeBlock('job',$job_info);
        }

$TBS->MergeBlock('sites',$sites);
$TBS->Show();


Thanks again, I'm lost!
By: David Christensen
Date: 2004-04-03
Time: 03:49

Re: n number of columns

In my many tries, I thought I'd just prepend the location to the $job_info[] array.  Then, I can treat everyting as just rows of data from one array.  Then just MergeBlock for each loop of $x:

No joy!  All the row are the same data.  Location0   Location0[Day0]   Location0[Day1] ...  Location0[DayN]

PHP:#####################################
# Merge the days array (from conf file) into template
###
$temp = array('name' => "&nbsp;");
array_unshift($days, $temp);
$TBS->MergeBlock('day',$days);

for ($x=0; $x < count($sites); $x++)
        {
        $job_info[] = $sites[$x];
        for ($count = 0; $count < $weeks; $count++)
                {
                $job_info[] = array('name' => $sites[$x]['name'] . "[Day$count]");
                #print "TEMP: " . $sites[$x]['name'] . "[Day$count]<br>\n";
                }

        #$TBS->MergeBlock('job',$job_info);
        $TBS->MergeBlock('site',$job_info);
        $job_info = array();
        }

$TBS->Show();


I can't seem to get it right.

I'm still lost!
By: Skrol29
Date: 2004-04-03
Time: 18:27

Re: n number of columns

Hi,

Your technic can't work because a block can be merged only once.
And in your main loop you have coded a MergBlock(), it works only the first time becasue afte there is no block definition left.

I have developped a web application that does quite the same as you're tring to do. Ecxept that in my application, I haven't an array that has an item for each cell.

Here is what I suggest to you:

HTML:
<table width="400" border="1">
  <tr>
    <td width="200">Site / Day </td>
    <td width="200"><strong>[day_title.name;block=td]</strong></td>
  </tr>
  <tr>
    <td><strong>[site.name;block=tr] </strong></td>
    <td>[data_d[day_cell.#;block=td]_s[site.#]]</td>
  </tr>
</table>

PHP:
$TBS->MergeBlock('day_title',$days);
$TBS->MergeBlock('day_cell',$days);
$TBS->MergeBlock('site',$sites);
...

When you have this, you should see the table with the correct number of rows and columns, and each cell is feeded with [data_dX_sY].
Then, in PHP, you add a double loop X,Y that replaces all strings "[data_dX_sY]" in $TBS->Source with the content you wish.

It worked fine for me.
By: NeedBeans
Date: 2004-04-05
Time: 10:59

Re: n number of columns

You should add this solution to the examples page, because I also spend quite some time in this problem. And there is no use in inventing the wheel again, if we already have a fine solution

Mike
By: Skrol29
Date: 2004-04-06
Time: 16:37

Re: n number of columns

Yep, that's a good idea.
I'm going to replace the "programmed loop" example.
By: David Christensen
Date: 2004-04-09
Time: 01:55

Re: n number of columns

I'm not sure I follow your PHP completely.  You have the "$days" array in both the 'day_title' MergeBlock as well as the 'day_cell' MergeBlock statements.  Are you implying that I should just append my 'day_cell' data the the "$days" array?

Like I said, I'm still lost.  I also looked at the "programmed loop" but it didn't look any different.

Thanks again!
By: Skrol29
Date: 2004-04-09
Time: 16:31

Re: n number of columns

Don't look at the "programmed loop" example, it has nothing to do with your problem. I just said, I'll swap this example with a future "dynamical column" example.

You don't have to append day_cell into $days.
Try the code I've sent sent (not tested) and look step by step what the PHP code does.

Your Html Table has 1 row with date titles followed by several rows with date values.
Because of Html Table structure, you first have to create the dynamic columns in 2 times: 1 for titles, and 1 for preparing rows.
Look at a standard table structure and you'll undsertand why it can't be one in one shot.
By: Skrol29
Date: 2004-04-09
Time: 16:31

Re: n number of columns

Don't look at the "programmed loop" example, it has nothing to do with your problem. I just said, I'll swap this example with a future "dynamical column" example.

You don't have to append day_cell into $days.
Try the code I've sent sent (not tested) and look step by step what the PHP code does.

Your Html Table has 1 row with date titles followed by several rows with date values.
Because of Html Table structure, you first have to create the dynamic columns in 2 times: 1 for titles, and 1 for preparing rows.
Look at a standard table structure and you'll undsertand why it can't be one in one shot.
By: David Christensen
Date: 2004-11-12
Time: 04:00

Re: n number of columns

I've finally figured out what you were talking about.  Hey, it only took my 7 months!  j/k. 

My problem now is I'm trying to also do 'x' number of rows of my 'n' columns.  So basically it is a dynamic matrix.

Is this possible?  I've tried:

<tr>
  <td>[client.name;block=tr]</td>
  <td>[policy.data1] - [policy.data2] - [policy.data3;block=td]</td>
</tr>

For whatever reason it spans columns, but only shows 1 row.
By: Skrol29
Date: 2004-11-13
Time: 01:49

Re: n number of columns

Hello David,

I don't understand why you have 2 blocks 'client' and 'policy'.
By: David Christensen
Date: 2004-11-13
Time: 01:55

Re: n number of columns

I may be doing it wrong.  I was just trying all different things to get it to do what I wanted.  My desire is to have both columns and rows be dynamic.  Basically, the rows are client data and the columns designate the start/end dates to query.

So depending on what data is returned based on the start/end date, that will dictate how many clients are returned and the number of columns.
By: CWL
Date: 2004-11-24
Time: 16:40

Re: n number of columns

Hi Skrol29,

Have you finally put an example of dynamicall column ?
I can't find it.

Because, I don't understand theses lines :

<td>[data_d[day_cell.#;block=td]_s[site.#]]</td>

What is data_d ? An Array ?

and

$TBS->MergeBlock('day_title',$days);
$TBS->MergeBlock('day_cell',$days);
By: CWL
Date: 2004-11-24
Time: 17:47

Re: n number of columns

it's fine, I understood

Actually, I try to resolve the following problem :
the first header line had 2 columns and the 2 header line had 4 columns. I have to find the solution to merge the columns of the 1st line to have a clear table...
By: Skrol29
Date: 2004-11-24
Time: 17:53

Re: n number of columns

> Have you finally put an example of dynamicall column ?

Not yet, sorry. It's on the ToDo.
By: David Christensen
Date: 2004-11-30
Time: 16:06

Re: n number of columns

I still cannot get this to work properly.  You asked before why I have 2 blocks, it is because I was following your example in a previous post in this thread (2004-04-03.)  I can get some output to fill all the columns and rows using this technique, but it shows incorrect data.  The first column (client name) is displayed correctly.  The other columns only seem to populate when I place the MergeBlock within a final loop.

To make things more complicated, I am using a complex array with 2 subkeys:

$data_arr[$client][$month]['failures']

This is because each row is specific to the $client and each column is specific to the $month.  "failures" is the specific data for that client/month to display in each cell.

If I loop through the clients, then loop through the months, I can get something to fill the table if I place the MergeBlock in the clients loop:

foreach ($clients as $client) {
    for ($month = $starmon; $month <= $lastmon; $month++) {
        $data_arr[$client][$month]['failures'] = $failures;
    }
    $TBS->MergeBlock('data',$data_arr[$client]);
}

with the template looking like:

<tr>
  <td>[client.name;block=tr]</td>
  <td>[data.failures;block=td]</td>
</tr>

By: Skrol29
Date: 2004-12-01
Time: 02:45

Re: n number of columns

Hello,

Can you draw what structure of data you have, and what kind of Html display you want to have.
By: David Christensen
Date: 2004-12-01
Time: 19:45

Re: n number of columns

I'm not sure I understand your last post?  I have a table, first column is client name.  Columns 1 - x contain data for the client on a monthly basis.  So there will be up to 12 columns.  Each is row displayed exactly the same just adjusting data for each client.

Depending on the criteria for the search, will determine what will be displayed as 1 - x (up to 12) columns and 1 - y (clients) rows.

My previous post show an example of the template I am using.
By: Skrol29
Date: 2004-12-01
Time: 23:47

Re: n number of columns

Hello,

I'm asking the structure of you data because I fill I miss some information.
For example, I can't see where is stored the name of the client.
Now you say it is in a table. So I guess the 'client' block is merged with a query on that table.
But what about the id of the client? Where does the variable $client come from, and what does it store ? I'm not sure to have all the pieces.
Did you choose to build $data_arr this way or do you have to?

Here is an example of solution that may help:
PHP:
// We merge the month columns. This must be done before merging the clients or other stufs.
$TBS->MergeBlock('month','num',array('min'=>$starmon,'max'=>$lastmon));

// We merge the clients
$TBS->MergeBlock('client',$connection,'SELECT id,name FROM client');

// failures will be automatically merged using the global varibale $data_arr

HTML:
<tr>
  <td>
      [client.name;block=tr]
  </td>
  <td>
      [var.data_arr.[client.id].[month.val,block=td].failures]
  </td>
</tr>
By: David Christensen
Date: 2004-12-02
Time: 00:59

Re: n number of columns

I'm sorry.  I was the one who was confused.  The raw data is stored in a PIPE delimited file/directory structure.  Each directory is client based and each file is date based.  So that is why I'm using an array to populate the template