PHP Classes

File: multiplecell.txt

Recommend this page to a friend!
  Classes of Peter Klauer   SQL Table   multiplecell.txt   Download  
File: multiplecell.txt
Role: Documentation
Content type: text/plain
Description: How to have multiple values per cell
Class: SQL Table
Output SQL query results as HTML tables
Author: By
Last change: The new second argument for the udf asked for a complete rewrite of this documentation. Although old code will still work it is recommended to use the new way: It is supposed to be leaner and faster.
Date: 17 years ago
Size: 1,831 bytes


Class file image Download
Last Change: 2006-05-04 This text file explains how to have multiple values output per cell. Every cell column in a sqltable represents a data column of the sql result. Every cell column therefore has only one value in it - initially. Using the sqltable::udf array you can parse a function to sqltable to deal with one (or more) of the cells. Example: Changing the column "id" to multiple values. In the code write: # define a user callback function named 'id_function' for the column 'id' $table->udf['id'] = 'id_function'; # The "id_function" needs to be defined like this: /** * This is a callback function for sqltable. Its name resides in * the sqltable::udf array. * @param string $id = original value of the column * @param array $sqlrowvars = array of all columns. Column names are the keys. * @return string */ function id_function( $id, $sqlrowvars ) { # # $value = $sqlrowvars['columnname']; // new way # # building a result string from $id (this cell) and other cells # $s = "<a href='edit.php?id=$id' title='edit me'>Edit</a> ". '<br>Date: '.$sqlrowvars['date']. '<br>Name: '.$sqlrowvars['name']; return( $s ); } Now the output of the table will show one cell with multiple values, but the original cells will still be displayed. Do not remove them from the sql statement! Just hide them: # the id column has a udf and therefore cannot be hidden $sqltable->hidden['date'] = 1; // hide column "date" $sqltable->hidden['name'] = 1; // hide column "name" Using sqltable::udf and the correct functions there are also html forms possible in each row of the table. The udf-functions always receive the original column value as the first parameter. The second parameter holds all the values from the whole row as a key-value-paired array.