We are trying to code a PHP page with a schedule that is dynamic. So we have multiple rooms and multiple speakers. We want the ability for it it to look like this with ROWSPAN in a dynamic way:

[ATTACH]4803[/ATTACH]

Our problem is when sessions overlap. (See the 3 columns) Our current code for sessions is an array:

    $_sp[]=array(
    "Name" => "Speaker 1",
    "Topic" => "Topic 1",
    "Day" => 1,
    "Time" => "9:00",
    "Meridiem" => "AM",
    "Room" => 1,
    "Minutes" => 90,
    );

$_sp[]=array(
"Name" => "Speaker 2",
"Topic" => "Topic 2",
"Day" => 1,
"Time" => "9:00",
"Meridiem" => "AM",
"Room" => 2,
"Minutes" => 45,
);

$_sp[]=array(
"Name" => "Speaker 3",
"Topic" => "Topic 3",
"Day" => 1,
"Time" => "9:00",
"Meridiem" => "AM",
"Room" => 3,
"Minutes" => 30,
);


$_sp[]=array(
"Name" => "Speaker 4",
"Topic" => "Topic 4",
"Day" => 1,
"Time" => "9:30",
"Meridiem" => "AM",
"Room" => 3,
"Minutes" => 30,
);

$_sp[]=array(
"Name" => "Speaker 5",
"Topic" => "Topic 5",
"Day" => 1,
"Time" => "9:45",
"Meridiem" => "AM",
"Room" => 2,
"Minutes" => 45,
);

$_sp[]=array(
"Name" => "Speaker 6",
"Topic" => "Topic 6",
"Day" => 1,
"Time" => "10:00",
"Meridiem" => "AM",
"Room" => 3,
"Minutes" => 30,
);

I do not know how to make the system figure out how to automatically figure out the number of rowspans to use and apply properly.

The output needs to be a table showing the schedule with the ROWSPAN to neaten the columns and the rows.

CORRECT HTML OUTPUT:

    <html><br><BODY><table border=2>
    <tr><td rowspan=18 valign="top">
    90 MIN SESSION<br><br>
    Speaker 1<br>
    Location: Room 1</td>
    <td rowspan=9  valign="top">
    45 MIN SESSION<br><br>
    Speaker 2<br>
    Location: Room 2</td>
    <td rowspan=6 valign="top">
    30 MIN SESSION<br><br>
    <br>Speaker 3<br>
    Location: Room 3</td>
    <td>9:00 AM row 1</td></tr>
    <tr><td>9:05 AM row 2</td></tr>
    <tr><td>9:10 AM row 3</td></tr>
    <tr><td>9:15 AM row 4</td></tr>
    <tr><td>9:20 AM row 5</td></tr>
    <tr><td>9:25 AM row 6</td></tr>
    <TR>
    <td rowspan=6  valign="top">
    30 MIN SESSION<br><br>
    <br>Speaker 4<br>
    Location: Room 3</td>
    <td>9:30 AM </td></tr>
    <tr><td>9:35 AM </td></tr>
    <tr><td>9:40 AM row 9</td></tr>
    <tr><td rowspan=9  valign="top">
    45 MIN SESSION<br><br>
    Speaker 5<br>
    Location: Room 2</td>
    </td><td>9:45 AM row 10</td></tr>
    <tr><td>9:50 AM row 11</td></tr>
    <tr><td>9:55 AM row 12</td></tr>
    <TR><td rowspan=6  valign="top">
    30 MIN SESSION<br><br>
    <br>Speaker 6<br>
    Location: Room 3</td>
    </td><td>10:00 AM row 13</td></tr>
    <tr><td>10:05 AMrow 14</td></tr>
    <tr><td>10:10 AMrow 15</td></tr>
    <tr><td>10:15 AMrow 16</td></tr>
    <tr><td>10:20 AMrow 17</td></tr>
    <tr><td>10:25 AMrow 18</td></tr>
    </table>
    </body>
    </html>

Which looks like the image above.

Any help is appreciated

del.jpg

    You'll have to do "count" on your array
    That will get you the overall row count but after that it looks like you are into doing loops, adding up the timings and working backwards to get the rowspans.

    Presumably an item could start or end at any 5 minute time, so that becomes your number base.. so if you can get it into arrays that have an entry for each 5 minute chunk, it will be closer to your output format.

    It's probably going to be easier to build it in chunks of html and at the end assemble them and echo them as needed - makes it simpler to swap item sequencing that way.

    Not sure if divs with specified heights might work better, maybe not.

    NOTE: re. the use of the word "session" - this is usually used to refer to a web browser "PHP session"
    So you might want to bear that in mind to disambiguate your "lectures" (if that is what they are) - not absolutely necessary but will make it clearer for people like me reading !!

      In the example above, each column is a room, with varied time lengths (Yes, we set 5 minute increments, that was the last column to show for scale).

      The problem is exactly what you see.

      PHP needs to know in column 2 that column 3 is 3 rows (30 mins) and because of that after Speaker#2 (45 mins) is 3 x <tr></tr>

      Having PHP analyze the array to determine how many <tr>'s to apply after a Cell is the issue.

        Unfortunately it's you that has to instruct PHP on how to do this!
        I gave some pointers and they should be enough to get you started.

        Also look up foreach which will allow you to step through the array and do some counting.

        A key question is where the $_sp array is getting its data from?
        If it's coming from a database you should be able to do some checks on the blocks of time at the database query stage, before attempting to do the output.

        It's not a complex job to do what you need, but it can be quite fiddly if you don't know the coding tools that are available and are most suitable.

          It may be easier to first build each column in its own array, then transpose the result. For example, consider if the data were arranged as:

          $d = array(
          	array(array('Speaker One', 'Room 1', 18)),
          	array(array('Speaker Two', 'Room 2', 9), array('Speaker Five', 'Room 2', 9)),
          	array(array('Speaker Three', 'Room 3', 6), array('Speaker Four', 'Room 3', 6), array('Speaker Six', 'Room 3', 6)),
          );
          

          It is of course an array. Each element is an array corresponding to one column of the final table (I guess that's the same thing as one room). Each element of a column array is one cell, and is itself an array of information relevant to one booking - speaker name, room number, and number of time slots the booking occupies (which is of course simply the duration divided by five minutes - this number is the rowspan for the cell representing the booking). Objects might be used to represent cells/bookings and columns/rooms instead of just arrays if you already have smarter data structures for those purposes. The contents of a cell need not be limited to actual bookings; an "empty" cell can be used to hold a room empty for a duration, and the last column in the HTML table would correspond to a final row of the above array looking something like [font=monospace]array(array('9:00 AM', 1), array('9:05 AM', 1), ...)[/font] so that the individual slots can be listed.

          To turn it into something more easily traversed while building the HTML table there's a trick I found in the manual:

          array_unshift($d, null);
          $t = call_user_func_array('array_map', $d);
          

          The result of that code on the above array is

          $t = array(
          array(array('Speaker One', 'Room 1', 18), array('Speaker Two', 'Room 2', 9), array('Speaker Three', 'Room 3', 6)),
          array(null,                               array('Speaker Five', 'Room 2', 9), array('Speaker Four', 'Room 3', 6)),
          array(null,                               null,                               array('Speaker Six', 'Room 3', 6))
          );
          

          And it's easy to use a pair of nested foreach loops (the outer one to loop over the rows, the inner one to loop over the cells in a row) and output whatever is appropriate for each cell as it is reached (using that 18 or 9 or whatever as the value of the cell's rowspan attribute). Just skip the nulls - they represent the cells that were obliterated by being spanned over by cells higher up.

            In the arrays, you mention, the 9 and the 6 for you are preset. We are looking at a dynamic table. So the speaker could be for 10 minutes, or 20, or 45 (5 minute increments are fine). The rowspan would depend on the relationship to the corresponding columns and the length of time of those sessions.

            Its the correlation for a dynamic table we are having a tough time figuring out.

            Also, we are finding one more problem: Rowspan with <tr></tr> appears differently in different browsers....has anyone found a way to universalize this?

              yorktown;11021453 wrote:

              Rowspan with <tr></tr> appears differently in different browsers....has anyone found a way to universalize this?

              rowspan needs to be defined in the td tag
              e.g.
              <tr>
              <td rowspan='2'>a</td>
              <td >b</td>
              <td >c</td>
              </tr>
              <tr>
              <td >b2</td>
              <td >c2</td>
              </tr>

                yorktown wrote:

                In the arrays, you mention, the 9 and the 6 for you are preset. We are looking at a dynamic table.

                No, I calculated them from the "Minutes" fields in your original arrays in the manner I described in the post: a 45-minute booking occupies (45 min)/(5 min/row) = 9 rows of the table.

                  Write a Reply...