Re: [PHPLIB] show_table_cells() example? From: Shawn Patton (shawn <email protected>)
Date: 10/27/99

Hello,

I see a situation where you would want to select all columns but only display
certain ones using the table class. Say you have 30 DB tables in a DB and all
these tables have an uid, ID and some_other_secret_column that you do not
want to display. Now, you are writing a generic script that works with any
and all of these DB tables to build a interface for editing/updating these tables.

Since you don't want to build different SELECTS for each DB table and want
one select to work on any of them , and since it is not possible to do SQL like
"SELECT (all columns except these ones) FROM table" this may be a situation
where you'd want to have your script skip the display of certain columns.

Well, this is definitly going against the grain but a simple way to stop the display
of these columns would be to directly modify the tables class by adding the following
line:
"if (ereg("^(uid|ID|some_other_secret_column)$", $key)) continue;"
in the filter check at or around line 841 in the function select_colnames():

  if (ereg($this->filter, $key))
     {
     if (ereg("^(uid|ID|some_other_secret_column)$", $key)) continue; // <- this line
     $this->fields[] = $key;
     }

-Shawn

Kristian Koehntopp wrote:

> Brian Knotts wrote:
> > >> I was just wondering if anyone has an example of the use of
> > >> show_table_cells().
> >
> > > What exactly are you trying to achieve?
> >
> > and instead of just dumping it all out with $t->show_result($db, "metadata"),
> > I'd like to only display certain columns, instead of all of them.
>
> If you want to suppress a complete table line, this could be
> your code, but this will still generate a opening <tr>, a
> checkbox (if requested) and a closing </tr> as well as any extra
> data. This is probably not what you require:
>
> class Subtable extends Table {
>
> function my_magic_condition(...) {
> return true; ## or false
> }
>
> ##
> ## This is a copy of the original implementation,
> ## except where marked as NEW.
> ##
> function show_table_cells($row, $row_key, $data, $class="")
> {
> global $debug;
>
> if ($debug)
> printf("<p>show_table_cells()<br>\n");
>
> if (!$this->verify_array($data))
> return 0;
>
> $cell = 0;
> $d = $this->select_colnames($data);
>
> ## NEW CODE
> if (!$this->my_magic_condition($row, $row_key, $data))
> return 1;
> ## END NEW CODE
>
> ## Create regular cells
> reset($d);
> while(list($key, $val) = each($d))
> {
> $this->table_cell($row, $cell++, $val, $data[$val], $class);
> }
>
> return 1;
>
> }
>
> You would instead work with a new table_row() function, because
> you can only suppress entire table rows in this place:
>
> class Subtable2 extends Table {
>
> function my_magic_condition(...) {
> return true; ## or false
> }
>
> function table_row($row, $row_key, $data, $class="")
> {
> global $debug;
>
> if ($debug)
> printf("<p>table_row()<br>\n");
>
> if (!$this->my_magic_condition(...))
> return;
>
> $d = $this->select_colnames($data);
> $this->table_row_open($row, $d, $class);
> $this->set_checkbox($row, $row_key, $data, $class);
> $this->show_table_cells($row, $row_key, $data, $class);
>
> # call virtual function
> if ($this->add_extra)
> $this->table_row_add_extra($row, $row_key, $data, $class);
>
> $this->table_row_close($row, $class);
> }
>
> }
>
> If working on a per-cell basis, it would be better to write this
> like this instead:
>
> class Subtable3 extends Table {
>
> function my_magic_condition(...) {
> return true; ## or false
> }
>
> ##
> ## Again, a copy except where shown
> ##
> function table_cell($row, $col, $key, $val, $class = "") {
> ## OK, I am at $row/$col in the table and
> ## display either $key or (most times) $val.
> if ($this->my_magic_condition($row, $col, $key, $val))
> printf("%s", $val);
> else
> printf("&nbsp;"); ## because I want HTML...
> }
> }
>
> Kristian
>
> --
> Kristian Köhntopp, NetUSE Kommunikationstechnologie GmbH
> Siemenswall, D-24107 Kiel, Germany, +49 431 386 436 00
> Using PHP3? See our web development library at
> http://phplib.netuse.de/ (We have moved! Update your bookmarks!)
> -
> PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
> To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
> the body, not the subject, of your message.

-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.