Page 1 of 1

Formatting empty table cells with php (SOLVED)

Posted: Sun Mar 20, 2011 1:53 pm
by joecanti
Hi all,

I'm looking for some php that I can add to my table in order to format the empty cells. All I want to do is have a litle bit of text come up on all the empty cells which says 'classroom free' or 'not booked' - is there a php comand that deals with this??

I'm using Drupal to output a table - it's a lesson planner. It has dates running down the side and classrooms along the top. If a classroom has been booked it outputs the name of the lesson in the cell on the right date. This is all working great, and allows a dynamic table on the site, but my client would like to have some default text in the cells that have not been booked.

Any ideas or pointers much appreciated!

Thanks, Joe

Re: Formatting empty table cells with php

Posted: Sun Mar 20, 2011 2:09 pm
by McInfo
Without seeing exactly how the table is generated in your code, all I can offer is some pseudo-code. Maybe there is some kind of loop in your code this can be applied to.

Code: Select all

while (there is a cell to be filled) {
    if (there is data for this cell) {
        print the data;
    } else {
        print the default message;
    }
}

Re: Formatting empty table cells with php

Posted: Sun Mar 20, 2011 2:33 pm
by joecanti
Hi McInfo,

Thanks for your reply. Yeah, that looks like the sort of thing. I'll have a scan through the code which creates the table and post back here - I'll try to find somewhere where it could go.

Will post back shortly, thanks again for your time, Joe

Re: Formatting empty table cells with php

Posted: Sun Mar 20, 2011 4:14 pm
by joecanti
Hi,

After digging through the code I found a useful bit in the render section which adds a space as a placeholder, so I dont need to add any more code - all I have done is change the placeholder from the space (&nbsp) to my default text 'classrom free'. Problem sorted :-)

Thanks for your original reply - it gave me a better idea for what I was looking for, and as it turned out a form of your code already existed to render the table content.

Cheers, all the best, Joe

Code: Select all

 $this->view->row_index = $row_index;
                $table['rows'][$row_header][$col_header] .= theme('tablegroup_item', $this->row_plugin->render($item));
              }
            }
            // empty cell, use a placeholder
            else {
              $table['rows'][$row_header][$col_header] = ' ';
            }
          }
        }

      // finally, render using the theme function
      $output .= theme($this->theme_functions(), $this->view, $this->options, $table, $title);
    }