Re: [phplib] Wie kann man die Ausgabe von table.inc von phplib gestalten? From: Jens Benecke (jens <email protected>)
Date: 08/17/01

On Thu, Aug 16, 2001 at 04:28:50PM +0200, Ralf Pfeiffer wrote:
> Hallo,
>
> ich verwende die die table-Klasse von phplib. Unter anderem die datei
> 'table.inc' als Ausgabe der Ergebnisse einer Datenbankabfrage von Mysql.
> Meine Frage: wie kann man die Form der Datenausgabe von table.inc
> beinflussen, z.B. dass man nur bestimmte Felder anzeigen kann, und daß
> man das Layout der Tabelle etwas anders gestaltet. Weiß jemand wie das
> geht oder wo man weitere Informationen hierüber bekommt?

AFAIK this is still an English list, so I'll reply in English to be on the
safe side. :)

I subclassed the table class to do exactly that (and added a couple
features). I explained in the attachment to this mail what I did.
Permission is hereby given to distribute this together with PHPLIB if
anyone cares (dares? :) to upload it into CVS.

-- 
Jens Benecke ········ http://www.hitchhikers.de/ - Europas Mitfahrzentrale

MSTD, n: MicroSoft Transmitted Disease. Propagates only due to Microsoft's insistence on distributing [software] that resembles Petri dishes. See also ILOVEYOU, Melissa, Code Red, Sircam, IIS. -- http://www.everything2.com/index.pl?node=MSTD

attached mail follows:


Hi,

for a database project I did some extensions to the table() class. Perhaps there is enough interest to clean them up a little and put them into the main phplib tree.

Hyperlinks in table cells ~~~~~~~~~~~~~~~~~~~~~~~~~ First, table_cell is rewritten to allow hyperlinks to another document, appending the current column name and the current value as parameters. For example, in a column called "ID" a table cell would not look like

523a but like <a href="details.php?ID=523a">523a</a>

if the array $make_links contained an ID element with the value "details.php".

This is the replacement method: --------------------------------------------------------------------------- class MyTable extends Table { # var $map_links = array();

function table_cell($row, $col, $key, $val, $class="") { $this->table_cell_open($class); if(isset($this->make_links[$key])) { # Es gibt schon einen Parameter an der URL dran -> "?"->"&" if(ereg("\?", $this->make_links[$key])) { $c = "&"; } else { $c = "?"; } printf("<a href=\"%s\">%s</a>", $this->make_links[$key].$c.$key."=".$val, $val); } else { printf("%s", $val); } $this->table_cell_close($class); } ---------------------------------------------------------------------------

New method for labeling the checkboxes that are optionally placed in the first column of a table row. I did this because I needed to know the (database) ID of the table row, not the number of the shown table row. So I set the counting element in "<input type=checkbox>" to something more sensible: The current value of the table column whose name is in $col_count. (which would ideally be a number or some sort of short ID.)

This enables me to put a submit button that "filters" selected table rows out of the lot.

--------------------------------------------------------------------------- function table_checkbox_cell($row, $row_key, $data, $class="") {

if(isset($this->col_count)) { $x = $data[$this->col_count]; } else { $x = $row; }

if ($this->check) { printf(" <td%s><input type=\"checkbox\" name=\"%s[%s]\" value=\"%s\"></td>\n", $class?" class=$class":"", $this->check, empty($data[$this->check])?$row_key:$data[$this->check], $x); } } ---------------------------------------------------------------------------

Suggestions welcome, as always... ;)

-- 
`Q: Why did they deprecate a.out support in linux?      http://www.linuxfaq.de  
 A: Because a nasty coff is bad for your ELF.'       http://www.hitchhikers.de    
                      --- James Simmons          http://www.pinguin.conetix.de     

  • application/pgp-signature attachment: stored

  • application/pgp-signature attachment: stored