PHP Classes
Icontem

File: multiplecell.txt


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Peter Klauer  >  SQL Table  >  multiplecell.txt  
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
 

Contents

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.

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products