Formatting empty table cells with php (SOLVED)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joecanti
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 1:42 pm

Formatting empty table cells with php (SOLVED)

Post 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
Last edited by joecanti on Sun Mar 20, 2011 4:15 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Formatting empty table cells with php

Post 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;
    }
}
joecanti
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 1:42 pm

Re: Formatting empty table cells with php

Post 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
joecanti
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 1:42 pm

Re: Formatting empty table cells with php

Post 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);
    }
Post Reply