views:

118

answers:

1

Ok, I have these 2 types of layouts, basically, it can be any layout really. I have decided to use tables for this, since using div tags cause undesirable results in some possible layout types.

Here are 2 pics that describe the returned results of row and column: alt text

This would return the $layout array like so:

$layout[0][0]
$layout[0][1]
$layout[1][1]

In this layout type: $layout[1][0] is NOT SET, or doesn't exist. Row 1, Column 0 doesn't exist in here. So how can we use this to help us determine the rowspans...?

alt text

Ok, this layout type would now return the following:

$layout[0][0]
$layout[0][1]
$layout[1][0]
$layout[2][0]
$layout[2][1]
$layout[3][1]

Again, there are some that are NOT SET in here:

$layout[1][1]
$layout[3][0]

Ok, I have an array called $layout that does a foreach on the row and column, but it doesn't grab the rows and columns that are NOT SET. So I created a for loop (with the correct counts of how many rows there are and how many columns there are). Here's what I got so far:

// $not_set = array();
for($x = 0; $x < $cols; $x++)
{
    $f = 0;
    for($p = 0; $p < $rows; $p++)
    {
        // $f = count($layout[$p]); 
        if(!isset($layout[$p][$x]))
        {
            $f++;
            // It could be a rowspan or a Colspan...
            // We need to figure out which 1 it is!

            /*
            $not_set[] = array(
                'row' => $p,
                'column' => $x,
            );
            */
        }

        // if ($rows - count($layout[$p]))

    }
}

Ok, the $layout array has 2 keys. The first 1 is [ row ] and the 2nd key is [ column ]. Now looping through them all and determining whether it's NOT SET, tells me that either a rowspan or a colspan needs to be put into something somewhere. I'm completely lost here.

Basically, I would like to have an array returned here, something like this:

$spans['row'][ row # ][ column # ] = Number of rowspans for that <td> element.
$spans['column'][ row # ][ column # ] = Number of colspans for that <td> element.

It's either going to need a colspan or a rowspan, it will definitely never need both for the same element. Also, the pics above show for only 2 columns, there can be more than 2 columns.

Any help at all would be greatly appreciated!! I've been driving myself crazy with this for days! Pllleaase...

A: 

Why not store the colspan & rowspan datum in the original array, rather than trying to derive them? Something like this:

$layout[0][0][1][1]
$layout[0][1][1][1]
$layout[1][0][2][1]
$layout[2][0][1][2]
$layout[2][1][1][1]
$layout[3][1][1][1]
graphicdivine
Hello, and thanks for your response :) The array keys for $layout go far beyond just the 2 key values. The 3rd Key in this array links to an id value for what content goes inside of this row and column. The $layout array is being populated with row and column values from the database, which get set when the user changes the layout. Are you saying I need to more columns in this table, called rowspan and colspan??
SoLoGHoST
Also, I know this is possible to do with just row and column, perhaps using array_keys somehow, or array_intersect_key? I have all of the info (total row count, total column count, # of columns per row, # of rows per column, etc. etc.). Why can't I use this info to get what I need?? Seems reasonable right?
SoLoGHoST
Reasonble? Yes.On the contrary, though, doesn't it also seem reasonable that if, at the point at which the user creates/edits the layout the arrangement of cells is established, that would be the point to capture and store that information. Otherwise you are building your layout twice.
graphicdivine
Hmm, I see your point. Good Point. Am thinking of a way to implement this into the database now. Perhaps I can turn the row and column columns into type string and do something like this: column = 0:2, row = 0:0. This would mean that position 0, 0 gets 2 colspans. Though I really don't like dealing with strings in the database unless it's absolutely needed. Though I suppose in this case it is.
SoLoGHoST
Maybe you can give me an example of how to use the approach you provided above??How do I get the # of rowspans/colspans from both keys for each row/column?
SoLoGHoST
Thanks, but this approach is no good. Isn't there anyone around that's good at math?
SoLoGHoST