begin process at 2012 05 27 16:36:50
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > AFFICHAGE TABLEAU AVEC TEMPLATE CLASSE

AFFICHAGE TABLEAU AVEC TEMPLATE CLASSE


 Information sur la source

Note :
Aucune note
Catégorie :Divers Niveau :Expert Date de création :23/08/2004 Date de mise à jour :05/01/2005 17:56:24 Vu / téléchargé :7 677 / 465

Auteur : GRenard

Ecrire un message privé
Site perso
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Ce script vous permettra d'afficher un tableau chargé en mémoire à l'avance.
Il y a plusieurs fonctions que vous pouvez explorer dans le fichier table.class.php ou directement dans la documentation fournie !
Avec ce script, vous n'aurez plus à taper <table><tr><td>... tout est automatique !

Compatible PHP4, PHP5
Vous devez obligatoirement mettre $null comme 4e paramètre si vous n'avez pas d'objet parent.
En PHP4, lorsque vous assignez l'objet à une variable et que vous voulez garder tous les liens des classes, il faut mettre la perluète &... ce qui donne
$obj =& new LSTable( 1, 1, '100', $other_table );
Normalement, si votre 4e paramètre est $null, il n'est pas nécessaire de sauvegarder le new LSTable avec la perluète.

Source

  • <?php
  • //////////////////////////////////////////////////////////////////////
  • // table.class.php
  • //--------------------------------------------------------------------
  • //
  • // Class Table - You can modify the define values
  • //
  • //--------------------------------------------------------------------
  • // Revision History
  • // v1.05 01 jan 2004 Jean-Sebastien Goupil - Adding check is_object when setText()
  • // v1.04 09 dec 2004 Jean-Sebastien Goupil - Correct ; after &nbsp;
  • // V1.03 23 sep 2004 Jean-Sebastien Goupil - Add Better Row,Col Span Function
  • // V1.02 26 aug 2004 Jean-Sebastien Goupil - Many Bugs Cor.
  • // V1.01 25 aug 2004 Jean-Sebastien Goupil - Error init Col
  • // V1.00 23 aug 2004 Jean-Sebastien Goupil
  • //--------------------------------------------------------------------
  • // Copyright (C) Jean-Sebastien Goupil
  • // http://other.lookstrike.com/
  • //--------------------------------------------------------------------
  • //////////////////////////////////////////////////////////////////////
  • define( 'TABLE_DEFAULT_ROW_HIDDEN', FALSE );
  • define( 'TABLE_DEFAULT_COL_HIDDEN', FALSE );
  • define( 'TABLE_DEFAULT_CELL_VALUE', '&nbsp;' ); // If '&nbsp;', a cell will appear, if NULL, no cell will appear
  • define( 'TABLE_DEFAULT_TEMPLATE', 'tpl_LS' );
  • include( 'template.php' );
  • class LSTable {
  • // PRIVATE ARGUMENTS
  • var $template; // string
  • var $numRows, $numCols; // int
  • var $title; // string
  • var $text = array(); // string
  • var $cellsAttributes = array(), $rowsAttributes = array(); // string
  • var $hiddenRows = array(), $hiddenCols = array(); // bool
  • var $width; // string
  • var $temp_col; // int
  • var $temp_ascending; // bool
  • // PUBLIC FUNCTIONS
  • /**
  • * @return
  • * @param int $numRows
  • * @param int $numCols
  • * @param string $width
  • * @param object $parent
  • * @desc Constructor. You can put a $parent object. This will search the first empty place into the parent.
  • **/
  • function LSTable ( $numRows, $numCols, $width, &$parent ) {
  • $this->numRows = intval( $numRows );
  • $this->numCols = intval( $numCols );
  • for( $i = 0; $i < $numRows; $i++ )
  • $this->_setVariable( $i );
  • for( $i = 0; $i < $numCols; $i++ )
  • $this->hiddenCols[ $i ] = TABLE_DEFAULT_COL_HIDDEN;
  • $this->title = '';
  • $this->width = strval( $width );
  • if( defined( 'TABLE_DEFAULT_TEMPLATE' ) )
  • $this->setTemplate( TABLE_DEFAULT_TEMPLATE );
  • // We look for an empty place if $parent isn't null
  • if( is_object( $parent ) ) {
  • $stop = false;
  • for( $i = 0; $i < $parent->numRows; $i++ ) {
  • for( $j = 0; $j < $parent->numCols; $j++ ) {
  • if( $parent->text[ $i ][ $j ] == TABLE_DEFAULT_CELL_VALUE ) {
  • $parent->text[ $i ][ $j ] =& $this;
  • $stop = true;
  • }
  • if( $stop == true )
  • break;
  • }
  • if( $stop == true )
  • break;
  • }
  • }
  • }
  • // No destructor for PHP4
  • //function __destruct() {
  • //
  • //}
  • /**
  • * @return void
  • * @param int $row
  • * @param int $col
  • * @param mixed $string
  • * @desc Writes Text or Object into $row and $col.
  • **/
  • function setText ( $row, $col, $string ) {
  • if( !is_object( $string ) )
  • $string = strval( $string );
  • if( is_int( $row ) && is_int( $col ) )
  • if( $row < $this->numRows && $col < $this->numCols )
  • $this->text[ $row ][ $col ] = $string;
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param int $col
  • * @param string $attrib
  • * @param mixed $value
  • * @desc Adds a Cell Attribute at $row and $col.
  • **/
  • function addCellAttribute ( $row, $col, $attrib, $value ) {
  • if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
  • if( $row < $this->numRows && $col < $this->numCols )
  • $this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] = $value;
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param int $col
  • * @param string $attrib
  • * @desc Deletes a Cell Attribute at $row and $col.
  • **/
  • function delCellAttribute ( $row, $col, $attrib ) {
  • if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
  • if( $row < $this->numRows && $col < $this->numCols )
  • unset( $this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] );
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param string $attrib
  • * @param mixed $value
  • * @desc Adds a Row Attribute at $row. Will be located in TR.
  • **/
  • function addRowAttribute ( $row, $attrib, $value ) {
  • if( is_int( $row ) && is_string( $attrib ) )
  • if( $row < $this->numRows )
  • $this->rowsAttributes[ $row ][ strtolower( $attrib ) ] = $value;
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param string $attrib
  • * @desc Deletes a Row Attribute at $row.
  • **/
  • function delRowAttribute ( $row, $attrib ) {
  • if( is_int( $row ) && is_string( $attrib ) )
  • if( $row < $this->numRows )
  • unset( $this->rowsAttributes[ $row ][ strtolower( $attrib ) ] );
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param string $attrib
  • * @param mixed $value
  • * @desc Adds a Cell Attribute in all cells located on $row row.
  • **/
  • function addAllCellsInRowAttribute ( $row, $attrib, $value ) {
  • if( is_int( $row ) && is_string( $attrib ) )
  • if( $row < $this->numRows )
  • for( $i = 0; $i < $this->numCols; $i++ )
  • $this->cellsAttributes[ $row ][ $i ][ strtolower( $attrib ) ] = $value;
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @param string $attrib
  • * @param mixed $value
  • * @desc Adds a Cell Attribute in all cells located on $col column.
  • **/
  • function addAllCellsInColAttribute ( $col, $attrib, $value ) {
  • if( is_int( $col ) && is_string( $attrib ) )
  • if( $col < $this->numCols )
  • for( $i = 0; $i < $this->numRows; $i++ )
  • $this->cellsAttributes[ $i ][ $col ][ strtolower( $attrib ) ] = $value;
  • }
  • /**
  • * @return void
  • * @param callback $template
  • * @desc Sets Template (Class)
  • **/
  • function setTemplate ( $template ) {
  • if( is_string( $template ) )
  • if( class_exists( $template ) )
  • $this->template = strval( $template );
  • }
  • /**
  • * @return string
  • * @desc Returns current Template
  • **/
  • function template () {
  • return $this->template;
  • }
  • /**
  • * @return mixed
  • * @param int $row
  • * @param int $col
  • * @desc Returns the text or object contained into $row and $col
  • **/
  • function text ( $row, $col ) {
  • if( is_int( $row ) && is_int( $col ) )
  • if( $row < $this->numRows && $col < $this->numCols )
  • return $this->text[ $row ][ $col ];
  • return FALSE;
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param int $col
  • * @desc Clears the cell located into $row and $col. Keeps the Cell.
  • */
  • function clearCell ( $row, $col ) {
  • if( is_int( $row ) && is_int( $col ) ) {
  • if( $row < $this->numRows && $col < $this->numCols ) {
  • $this->text[ $row ][ $col ] = TABLE_DEFAULT_CELL_VALUE;
  • unset( $this->cellsAttributes[ $row ][ $col ] );
  • $this->cellsAttributes[ $row ][ $col ] = array();
  • }
  • }
  • }
  • /**
  • * @return int
  • * @desc Returns the number of Rows
  • **/
  • function numRows () {
  • return $this->numRows;
  • }
  • /**
  • * @return int
  • * @desc Returns the number of Columns
  • **/
  • function numCols () {
  • return $this->numCols;
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @param bool $ascending
  • * @desc Sorts table based on $col.
  • **/
  • function sortColumn ( $col, $ascending = TRUE ) {
  • if( is_int( $col ) && is_bool( $ascending ) ) {
  • if( $col < $this->numCols ) {
  • $this->temp_col = $col;
  • $this->temp_ascending = $ascending;
  • $this->_sort_merge( $this->text );
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $r
  • * @desc Sets the number of rows of the table.
  • **/
  • function setNumRows ( $r ) {
  • if( is_int( $r ) )
  • if( $r >= 0 )
  • if( $r > $this->numRows )
  • $this->insertRows( $this->numRows, $r - $this->numRows );
  • elseif( $r < $this->numRows )
  • for( $i = $this->numRows; $i > $r; $i-- )
  • $this->removeRow( $i - 1 );
  • }
  • /**
  • * @return void
  • * @param int $r
  • * @desc Sets the number of columns of the table.
  • **/
  • function setNumCols ( $r ) {
  • if( is_int( $r ) )
  • if( $r >= 0 )
  • if( $r > $this->numCols )
  • $this->insertColumns( $this->numCols, $r - $this->numCols );
  • elseif( $r < $this->numCols )
  • for( $i = $this->numCols; $i > $r; $i-- )
  • $this->removeColumn( $i - 1 );
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @desc Hides a $row from table
  • **/
  • function hideRow ( $row ) {
  • if( is_int( $row ) )
  • if( $row < $this->numRows )
  • $this->hiddenRows[ $row ] = TRUE;
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @desc Hides a $col from table
  • **/
  • function hideColumn ( $col ) {
  • if( is_int( $col ) )
  • if( $col < $this->numCols )
  • $this->hiddenCols[ $col ] = TRUE;
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @desc Shows a $row from table
  • **/
  • function showRow ( $row ) {
  • if( is_int( $row ) )
  • if( $row < $this->numRows )
  • $this->hiddenRows[ $row ] = FALSE;
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @desc Shows a $col from table
  • **/
  • function showColumn ( $col ) {
  • if( is_int( $col ) )
  • if( $col < $this->numCols )
  • $this->hiddenCols[ $col ] = FALSE;
  • }
  • /**
  • * @return bool
  • * @param int $row
  • * @desc Returns TRUE if a row is hidden.
  • **/
  • function isRowHidden ( $row ) {
  • if( is_int( $row ) )
  • if( $row < $this->numRows )
  • return $this->hiddenRows[ $row ];
  • return FALSE;
  • }
  • /**
  • * @return bool
  • * @param int $col
  • * @desc Returns TRUE if a col is hidden.
  • **/
  • function isColumnHidden ( $col ) {
  • if( is_int( $col ) )
  • if( $col < $this->numCols )
  • return $this->hiddenCols[ $col ];
  • return FALSE;
  • }
  • /**
  • * @return void
  • * @param int $row1
  • * @param int $row2
  • * @param bool $swapAttributes
  • * @desc Swaps 2 rows. Swaps attributes if $switchAttributes is TRUE.
  • **/
  • function swapRows ( $row1, $row2, $swapAttributes = FALSE ) {
  • if( is_int( $row1 ) && is_int( $row2 ) && is_bool( $swapAttributes ) ) {
  • if( $row1 < $this->numRows && $row2 < $this->numRows ) {
  • $temp =& $this->text[ $row1 ];
  • $this->text[ $row1 ] =& $this->text[ $row2 ];
  • $this->text[ $row2 ] =& $temp;
  • if( $swapAttributes == TRUE ) {
  • $temp2 = $this->cellsAttributes[ $row1 ];
  • $this->cellsAttributes[ $row1 ] = $this->cellsAttributes[ $row2 ];
  • $this->cellsAttributes[ $row2 ] = $temp2;
  • $temp2 = $this->rowsAttributes[ $row1 ];
  • $this->rowsAttributes[ $row1 ] = $this->rowsAttributes[ $row2 ];
  • $this->rowsAttributes[ $row2 ] = $temp2;
  • }
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $col1
  • * @param int $col2
  • * @param bool $swapAttributes
  • * @desc Swaps 2 cols. Swaps attributes if $switchAttributes is TRUE.
  • **/
  • function swapColumns ( $col1, $col2, $swapAttributes = FALSE ) {
  • if( is_int( $col1 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
  • if( $col1 < $this->numCols && $col2 < $this->numCols ) {
  • for( $i = 0; $i < $this->numRows; $i++ ){
  • $temp =& $this->text[ $i ][ $col1 ];
  • $this->text[ $i ][ $col1 ] =& $this->text[ $i ][ $col2 ];
  • $this->text[ $i ][ $col2 ] =& $temp;
  • if( $swapAttributes == TRUE ) {
  • $temp2 = $this->cellsAttributes[ $i ][ $col1 ];
  • $this->cellsAttributes[ $i ][ $col1 ] = $this->cellsAttributes[ $i ][ $col2 ];
  • $this->cellsAttributes[ $i ][ $col2 ] = $temp2;
  • }
  • }
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $row1
  • * @param int $col1
  • * @param int $row2
  • * @param int $col2
  • * @param bool $swapAttributes
  • * @desc Swaps 2 cells. Swaps attributes if $switchAttributes is TRUE.
  • **/
  • function swapCells ( $row1, $col1, $row2, $col2, $swapAttributes = FALSE ) {
  • if( is_int( $row1 ) && is_int( $col1 ) && is_int( $row2 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
  • if( $row1 < $this->numRows && $col1 < $this->numCols && $row2 < $this->numRows && $col2 < $this->numCols ) {
  • $temp =& $this->text[ $row1 ][ $col1 ];
  • $this->text[ $row1 ][ $col1 ] =& $this->text[ $row2 ][ $col2 ];
  • $this->text[ $row2 ][ $col2 ] =& $temp;
  • if( $swapAttributes == TRUE ) {
  • $temp2 = $this->cellsAttributes[ $row1 ][ $col1 ];
  • $this->cellsAttributes[ $row1 ][ $col1 ] = $this->cellsAttributes[ $row2 ][ $col2 ];
  • $this->cellsAttributes[ $row2 ][ $col2 ] = $temp2;
  • }
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @param int $count
  • * @desc Inserts $count row at $row position.
  • **/
  • function insertRows ( $row, $count = 1 ) {
  • if( is_int( $row ) && is_int( $count ) ) {
  • if( $row >= 0 && $row <= $this->numRows ) {
  • for( $i = 0; $i < $count; $i++) {
  • array_splice( $this->text, $row, 0, '' );
  • array_splice( $this->hiddenRows, $row, 0, FALSE );
  • array_splice( $this->cellsAttributes, $row, 0, FALSE );
  • array_splice( $this->rowsAttributes, $row, 0, FALSE );
  • $this->_setVariable( $row );
  • $this->numRows += 1;
  • }
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @param int $count
  • * @desc Inserts $count columns at $col position.
  • **/
  • function insertColumns ( $col, $count = 1 ) {
  • if( is_int( $col ) && is_int( $count ) ) {
  • if( $col >= 0 && $col <= $this->numCols ) {
  • for( $i = 0; $i < $this->numRows; $i++ ) {
  • $temp_text = array();
  • $temp_attributes = array();
  • reset($this->text[ $i ]);
  • for( $j = 0; $j <= $this->numCols; $j++ ) {
  • if( $col == $j ) {
  • for( $k = 0; $k < $count; $k++ ){
  • $temp_text[] = '';
  • $temp_attributes[] = array();
  • }
  • }
  • if( $j == $this->numCols )
  • break;
  • $temp_text[] = $this->text[ $i ][ $j ];
  • $temp_attributes[] = $this->cellsAttributes[ $i ][ $j ];
  • }
  • $this->text[ $i ] = $temp_text;
  • $this->cellsAttributes[ $i ] = $temp_attributes;
  • }
  • for( $i = 0; $i < $count; $i++ )
  • array_splice( $this->hiddenCols, $col, 0, FALSE );
  • $this->numCols += $count;
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $row
  • * @desc Removes $row.
  • **/
  • function removeRow ( $row ) {
  • if( is_int( $row ) ) {
  • if( $row < $this->numRows ) {
  • array_splice( $this->text, $row, 1 );
  • array_splice( $this->hiddenRows, $row, 1 );
  • array_splice( $this->cellsAttributes, $row, 1 );
  • array_splice( $this->rowsAttributes, $row, 1 );
  • $this->numRows -= 1;
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $col
  • * @desc Removes $col.
  • **/
  • function removeColumn ( $col ) {
  • if( is_int( $col ) ) {
  • if( $col < $this->numCols ) {
  • for( $i = 0; $i < $this->numRows; $i++ ) {
  • $temp_text = array();
  • $temp_attributes = array();
  • reset($this->text[ $i ]);
  • while ( list( $key, ) = each( $this->text[ $i ] ) ) {
  • if( $key != $col ) {
  • $temp_text[] = $this->text[ $i ][ $key ];
  • $temp_attributes[] = $this->cellsAttributes[ $i ][ $key ];
  • }
  • }
  • $this->text[ $i ] = $temp_text;
  • $this->cellsAttributes[ $i ] = $temp_attributes;
  • }
  • array_splice( $this->hiddenCols, $col, 1 );
  • $this->numCols -= 1;
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $width
  • * @desc Sets Table Width.
  • **/
  • function setWidth ( $width ) {
  • if( is_string( $width ) )
  • $this->width = strval( $width );
  • }
  • /**
  • * @return string
  • * @desc Returns Table Width.
  • **/
  • function width () {
  • return $this->width;
  • }
  • /**
  • * @return void
  • * @param int $title
  • * @desc Sets Table Title.
  • **/
  • function setTitle ( $title ) {
  • if( is_string( $title ) )
  • $this->title = strval( $title );
  • }
  • /**
  • * @return string
  • * @desc Returns Table Title.
  • **/
  • function title () {
  • return $this->title;
  • }
  • /**
  • * @return void
  • * @desc Displays the table with its cells.
  • **/
  • function draw () {
  • if( $this->template != '' ) {
  • $tpl = new $this->template;
  • $tpl->__header( $this->width, $this->title );
  • $this->_check_rowcol_span();
  • for( $i = 0; $i < $this->numRows; $i++ ) {
  • if( $this->hiddenRows[ $i ] == FALSE ) {
  • $tpl->__row_start( $this->rowsAttributes[ $i ] );
  • for( $j = 0; $j < $this->numCols; $j++ ) {
  • if( $this->hiddenCols[ $j ] == FALSE ) {
  • if( $this->text[ $i ][ $j ] !== NULL ) {
  • if( is_object( $this->text[ $i ][ $j ] ) ) {
  • $tpl->__cell_start( '', $this->cellsAttributes[ $i ][ $j ] );
  • $this->text[ $i ][ $j ]->draw();
  • }
  • else
  • $tpl->__cell_start( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
  • $tpl->__cell_stop( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
  • }
  • }
  • }
  • $tpl->__row_stop( $this->rowsAttributes[ $i ] );
  • }
  • }
  • $tpl->__footer( $this->width, $this->title );
  • }
  • }
  • // PRIVATE FUNCTIONS
  • /**
  • * @return void
  • * @desc Sets NULL to cells if colspan or rowspan go on the cells
  • **/
  • function _check_rowcol_span() {
  • for( $i = 0; $i < $this->numRows; $i++ ) {
  • for( $j = 0; $j < $this->numCols; $j++ ) {
  • if( isset( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ) )
  • if( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] > 0 )
  • for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ); $z++ )
  • $this->text[ $i ][ $j + $z ] = NULL;
  • if( isset( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ) )
  • if( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] > 0 )
  • for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ); $z++ )
  • $this->text[ $i + $z ][ $j ] = NULL;
  • }
  • }
  • }
  • /**
  • * @return void
  • * @param int $r
  • * @desc Sets Default Variables for row $r.
  • **/
  • function _setVariable ( $r ) {
  • $this->text[ $r ] = array_fill( 0, $this->numCols, TABLE_DEFAULT_CELL_VALUE );
  • $this->cellsAttributes[ $r ] = array_fill( 0, $this->numCols, array() );
  • $this->rowsAttributes[ $r ] = array();
  • $this->hiddenRows[ $r ] = TABLE_DEFAULT_ROW_HIDDEN;
  • }
  • /**
  • * @return void
  • * @param int $r
  • * @desc Unsets Default Variables for row $r.
  • **/
  • function _unsetVariable ( $r ) {
  • unset( $this->text[ $r ] );
  • unset( $this->cellsAttributes[ $r ] );
  • unset( $this->rowsAttributes[ $r ] );
  • unset( $this->hiddenRows[ $r ] );
  • }
  • /**
  • * @return void
  • * @param string $tab
  • * @desc Merge Function
  • **/
  • function _sort_merge ( &$tab ) {
  • if( count( $tab ) <= 1 ) return;
  • else {
  • $tab1 = array();
  • $tab2 = array();
  • for( $i = 0; $i < count( $tab ); $i++) {
  • if( $i < ( count( $tab ) ) / 2 )
  • $tab1[] = $tab[ $i ];
  • else
  • $tab2[] = $tab[ $i ];
  • }
  • $this->_sort_merge( $tab1 );
  • $this->_sort_merge( $tab2 );
  • $this->_merge_all( $tab1, $tab2, $tab );
  • }
  • }
  • /**
  • * @return void
  • * @param string $tab1
  • * @param string $tab2
  • * @param string $tab
  • * @desc Merge Function
  • **/
  • function _merge_all ( $tab1, $tab2, &$tab ) {
  • $i = 0;
  • $i1 = $i2 = 0;
  • while( $i1 < count( $tab1 ) && $i2 < count( $tab2 ) ) {
  • if( strcmp( $tab1[ $i1 ][ $this->temp_col ], $tab2[ $i2 ][ $this->temp_col ] ) == (($this->temp_ascending==TRUE)?-1:1) )
  • $tab[ $i ] = $tab1[ $i1++ ];
  • else
  • $tab[ $i ] = $tab2[ $i2++ ];
  • $i++;
  • }
  • while( $i1 < count( $tab1 ) ) {
  • $tab[ $i ] = $tab1[ $i1++ ];
  • $i++;
  • }
  • while( $i2 < count( $tab2 ) ) {
  • $tab[ $i ] = $tab2[ $i2++ ];
  • $i++;
  • }
  • }
  • }
  • ?>
<?php
//////////////////////////////////////////////////////////////////////
// table.class.php
//--------------------------------------------------------------------
//
// Class Table - You can modify the define values
//
//--------------------------------------------------------------------
// Revision History
// v1.05	01 jan	2004	Jean-Sebastien Goupil - Adding check is_object when setText()
// v1.04	09 dec	2004	Jean-Sebastien Goupil - Correct ; after &nbsp;
// V1.03	23 sep	2004	Jean-Sebastien Goupil - Add Better Row,Col Span Function
// V1.02	26 aug	2004	Jean-Sebastien Goupil - Many Bugs Cor.
// V1.01	25 aug	2004	Jean-Sebastien Goupil - Error init Col
// V1.00	23 aug	2004	Jean-Sebastien Goupil
//--------------------------------------------------------------------
// Copyright (C) Jean-Sebastien Goupil
// http://other.lookstrike.com/
//--------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
define( 'TABLE_DEFAULT_ROW_HIDDEN', FALSE );
define( 'TABLE_DEFAULT_COL_HIDDEN', FALSE );
define( 'TABLE_DEFAULT_CELL_VALUE', '&nbsp;' );	// If '&nbsp;', a cell will appear, if NULL, no cell will appear
define( 'TABLE_DEFAULT_TEMPLATE', 'tpl_LS' );

include( 'template.php' );
class LSTable {
	// PRIVATE ARGUMENTS
	var $template;							// string
	var $numRows, $numCols;						// int
	var $title;							// string
	var $text = array();						// string
	var $cellsAttributes = array(), $rowsAttributes = array();	// string
	var $hiddenRows = array(), $hiddenCols = array();		// bool
	var $width;							// string

	var $temp_col;							// int
	var $temp_ascending;						// bool

	// PUBLIC FUNCTIONS
	/**
	* @return
	* @param int $numRows
	* @param int $numCols
	* @param string $width
	* @param object $parent
	* @desc Constructor. You can put a $parent object. This will search the first empty place into the parent.
	**/
	function LSTable ( $numRows, $numCols, $width, &$parent ) {
		$this->numRows = intval( $numRows );
		$this->numCols = intval( $numCols );
		for( $i = 0; $i < $numRows; $i++ )
			$this->_setVariable( $i );
		for( $i = 0; $i < $numCols; $i++ )
			$this->hiddenCols[ $i ] = TABLE_DEFAULT_COL_HIDDEN;
		$this->title = '';
		$this->width = strval( $width );

		if( defined( 'TABLE_DEFAULT_TEMPLATE' ) )
			$this->setTemplate( TABLE_DEFAULT_TEMPLATE );

		// We look for an empty place if $parent isn't null
		if( is_object( $parent ) ) {
			$stop = false;
			for( $i = 0; $i < $parent->numRows; $i++ ) {
				for( $j = 0; $j < $parent->numCols; $j++ ) {
					if( $parent->text[ $i ][ $j ] == TABLE_DEFAULT_CELL_VALUE ) {
						$parent->text[ $i ][ $j ] =& $this;
						$stop = true;
					}
					if( $stop == true )
						break;
				}
				if( $stop == true )
					break;
			}
		}
	}

	// No destructor for PHP4
	//function __destruct() {
	//
	//}

	/**
	* @return void
	* @param int $row
	* @param int $col
	* @param mixed $string
	* @desc Writes Text or Object into $row and $col.
	**/
	function setText ( $row, $col, $string ) {
		if( !is_object( $string ) )
			$string = strval( $string );
		if( is_int( $row ) && is_int( $col ) )
			if( $row < $this->numRows && $col < $this->numCols )
				$this->text[ $row ][ $col ] = $string;
	}

	/**
	* @return void
	* @param int $row
	* @param int $col
	* @param string $attrib
	* @param mixed $value
	* @desc Adds a Cell Attribute at $row and $col.
	**/
	function addCellAttribute ( $row, $col, $attrib, $value ) {
		if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
			if( $row < $this->numRows && $col < $this->numCols )
				$this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] = $value;
	}

	/**
	* @return void
	* @param int $row
	* @param int $col
	* @param string $attrib
	* @desc Deletes a Cell Attribute at $row and $col.
	**/
	function delCellAttribute ( $row, $col, $attrib ) {
		if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
			if( $row < $this->numRows && $col < $this->numCols )
				unset( $this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] );
	}

	/**
	* @return void
	* @param int $row
	* @param string $attrib
	* @param mixed $value
	* @desc Adds a Row Attribute at $row. Will be located in TR.
	**/
	function addRowAttribute ( $row, $attrib, $value ) {
		if( is_int( $row ) && is_string( $attrib ) )
			if( $row < $this->numRows )
				$this->rowsAttributes[ $row ][ strtolower( $attrib ) ] = $value;
	}

	/**
	* @return void
	* @param int $row
	* @param string $attrib
	* @desc Deletes a Row Attribute at $row.
	**/
	function delRowAttribute ( $row, $attrib ) {
		if( is_int( $row ) && is_string( $attrib ) )
			if( $row < $this->numRows )
				unset( $this->rowsAttributes[ $row ][ strtolower( $attrib ) ] );
	}

	/**
	* @return void
	* @param int $row
	* @param string $attrib
	* @param mixed $value
	* @desc Adds a Cell Attribute in all cells located on $row row.
	**/
	function addAllCellsInRowAttribute ( $row, $attrib, $value ) {
		if( is_int( $row ) && is_string( $attrib ) )
			if( $row < $this->numRows )
				for( $i = 0; $i < $this->numCols; $i++ )
					$this->cellsAttributes[ $row ][ $i ][ strtolower( $attrib ) ] = $value;
	}

	/**
	* @return void
	* @param int $col
	* @param string $attrib
	* @param mixed $value
	* @desc Adds a Cell Attribute in all cells located on $col column.
	**/
	function addAllCellsInColAttribute ( $col, $attrib, $value ) {
		if( is_int( $col ) && is_string( $attrib ) )
			if( $col < $this->numCols )
				for( $i = 0; $i < $this->numRows; $i++ )
					$this->cellsAttributes[ $i ][ $col ][ strtolower( $attrib ) ] = $value;
	}

	/**
	* @return void
	* @param callback $template
	* @desc Sets Template (Class)
	**/
	function setTemplate ( $template ) {
		if( is_string( $template ) )
			if( class_exists( $template ) )
				$this->template = strval( $template );
	}

	/**
	* @return string
	* @desc Returns current Template
	**/
	function template () {
		return $this->template;
	}

	/**
	* @return mixed
	* @param int $row
	* @param int $col
	* @desc Returns the text or object contained into $row and $col
	**/
	function text ( $row, $col ) {
		if( is_int( $row ) && is_int( $col ) )
			if( $row < $this->numRows && $col < $this->numCols )
				return $this->text[ $row ][ $col ];
		return FALSE;
	}

	/**
	* @return void
	* @param int $row
	* @param int $col
	* @desc Clears the cell located into $row and $col. Keeps the Cell.
	*/
	function clearCell ( $row, $col ) {
		if( is_int( $row ) && is_int( $col ) ) {
			if( $row < $this->numRows && $col < $this->numCols ) {
				$this->text[ $row ][ $col ] = TABLE_DEFAULT_CELL_VALUE;
				unset( $this->cellsAttributes[ $row ][ $col ] );
				$this->cellsAttributes[ $row ][ $col ] = array();
			}
		}
	}

	/**
	* @return int
	* @desc Returns the number of Rows
	**/
	function numRows () {
		return $this->numRows;
	}

	/**
	* @return int
	* @desc Returns the number of Columns
	**/
	function numCols () {
		return $this->numCols;
	}

	/**
	* @return void
	* @param int $col
	* @param bool $ascending
	* @desc Sorts table based on $col.
	**/
	function sortColumn ( $col, $ascending = TRUE ) {
		if( is_int( $col ) && is_bool( $ascending ) ) {
			if( $col < $this->numCols ) {
				$this->temp_col = $col;
				$this->temp_ascending = $ascending;
				$this->_sort_merge( $this->text );
			}
		}
	}

	/**
	* @return void
	* @param int $r
	* @desc Sets the number of rows of the table.
	**/
	function setNumRows ( $r ) {
		if( is_int( $r ) )
			if( $r >= 0 )
				if( $r > $this->numRows )
					$this->insertRows( $this->numRows, $r - $this->numRows );
				elseif( $r < $this->numRows )
					for( $i = $this->numRows; $i > $r; $i-- )
						$this->removeRow( $i - 1 );
	}

	/**
	* @return void
	* @param int $r
	* @desc Sets the number of columns of the table.
	**/
	function setNumCols ( $r ) {
		if( is_int( $r ) )
			if( $r >= 0 )
				if( $r > $this->numCols )
					$this->insertColumns( $this->numCols, $r - $this->numCols );
				elseif( $r < $this->numCols )
					for( $i = $this->numCols; $i > $r; $i-- )
						$this->removeColumn( $i - 1 );
	}

	/**
	* @return void
	* @param int $row
	* @desc Hides a $row from table
	**/
	function hideRow ( $row ) {
		if( is_int( $row ) )
			if( $row < $this->numRows )
				$this->hiddenRows[ $row ] = TRUE;
	}

	/**
	* @return void
	* @param int $col
	* @desc Hides a $col from table
	**/
	function hideColumn ( $col ) {
		if( is_int( $col ) )
			if( $col < $this->numCols )
				$this->hiddenCols[ $col ] = TRUE;
	}

	/**
	* @return void
	* @param int $row
	* @desc Shows a $row from table
	**/
	function showRow ( $row ) {
		if( is_int( $row ) )
			if( $row < $this->numRows )
				$this->hiddenRows[ $row ] = FALSE;
	}

	/**
	* @return void
	* @param int $col
	* @desc Shows a $col from table
	**/
	function showColumn ( $col ) {
		if( is_int( $col ) )
			if( $col < $this->numCols )
				$this->hiddenCols[ $col ] = FALSE;
	}

	/**
	* @return bool
	* @param int $row
	* @desc Returns TRUE if a row is hidden.
	**/
	function isRowHidden ( $row ) {
		if( is_int( $row ) )
			if( $row < $this->numRows )
				return $this->hiddenRows[ $row ];
		return FALSE;
	}

	/**
	* @return bool
	* @param int $col
	* @desc Returns TRUE if a col is hidden.
	**/
	function isColumnHidden ( $col ) {
		if( is_int( $col ) )
			if( $col < $this->numCols )
				return $this->hiddenCols[ $col ];
		return FALSE;
	}

	/**
	* @return void
	* @param int $row1
	* @param int $row2
	* @param bool $swapAttributes
	* @desc Swaps 2 rows. Swaps attributes if $switchAttributes is TRUE.
	**/
	function swapRows ( $row1, $row2, $swapAttributes = FALSE ) {
		if( is_int( $row1 ) && is_int( $row2 ) && is_bool( $swapAttributes ) ) {
			if( $row1 < $this->numRows && $row2 < $this->numRows ) {
				$temp =& $this->text[ $row1 ];
				$this->text[ $row1 ] =& $this->text[ $row2 ];
				$this->text[ $row2 ] =& $temp;
				if( $swapAttributes == TRUE ) {
					$temp2 = $this->cellsAttributes[ $row1 ];
					$this->cellsAttributes[ $row1 ] = $this->cellsAttributes[ $row2 ];
					$this->cellsAttributes[ $row2 ] = $temp2;

					$temp2 = $this->rowsAttributes[ $row1 ];
					$this->rowsAttributes[ $row1 ] = $this->rowsAttributes[ $row2 ];
					$this->rowsAttributes[ $row2 ] = $temp2;
				}
			}
		}
	}

	/**
	* @return void
	* @param int $col1
	* @param int $col2
	* @param bool $swapAttributes
	* @desc Swaps 2 cols. Swaps attributes if $switchAttributes is TRUE.
	**/
	function swapColumns ( $col1, $col2, $swapAttributes = FALSE ) {
		if( is_int( $col1 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
			if( $col1 < $this->numCols && $col2 < $this->numCols ) {
				for( $i = 0; $i < $this->numRows; $i++ ){
					$temp =& $this->text[ $i ][ $col1 ];
					$this->text[ $i ][ $col1 ] =& $this->text[ $i ][ $col2 ];
					$this->text[ $i ][ $col2 ] =& $temp;
					if( $swapAttributes == TRUE ) {
						$temp2 = $this->cellsAttributes[ $i ][ $col1 ];
						$this->cellsAttributes[ $i ][ $col1 ] = $this->cellsAttributes[ $i ][ $col2 ];
						$this->cellsAttributes[ $i ][ $col2 ] = $temp2;
					}
				}
			}
		}
	}

	/**
	* @return void
	* @param int $row1
	* @param int $col1
	* @param int $row2
	* @param int $col2
	* @param bool $swapAttributes
	* @desc Swaps 2 cells. Swaps attributes if $switchAttributes is TRUE.
	**/
	function swapCells ( $row1, $col1, $row2, $col2, $swapAttributes = FALSE ) {
		if( is_int( $row1 ) && is_int( $col1 ) && is_int( $row2 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
			if( $row1 < $this->numRows && $col1 < $this->numCols && $row2 < $this->numRows && $col2 < $this->numCols ) {
				$temp =& $this->text[ $row1 ][ $col1 ];
				$this->text[ $row1 ][ $col1 ] =& $this->text[ $row2 ][ $col2 ];
				$this->text[ $row2 ][ $col2 ] =& $temp;
				if( $swapAttributes == TRUE ) {
					$temp2 = $this->cellsAttributes[ $row1 ][ $col1 ];
					$this->cellsAttributes[ $row1 ][ $col1 ] = $this->cellsAttributes[ $row2 ][ $col2 ];
					$this->cellsAttributes[ $row2 ][ $col2 ] = $temp2;
				}
			}
		}
	}

	/**
	* @return void
	* @param int $row
	* @param int $count
	* @desc Inserts $count row at $row position.
	**/
	function insertRows ( $row, $count = 1 ) {
		if( is_int( $row ) && is_int( $count ) ) {
			if( $row >= 0 && $row <= $this->numRows ) {
				for( $i = 0; $i < $count; $i++) {
					array_splice( $this->text, $row, 0, '' );
					array_splice( $this->hiddenRows, $row, 0, FALSE );
					array_splice( $this->cellsAttributes, $row, 0, FALSE );
					array_splice( $this->rowsAttributes, $row, 0, FALSE );
					$this->_setVariable( $row );
					$this->numRows += 1;
				}
			}
		}
	}

	/**
	* @return void
	* @param int $col
	* @param int $count
	* @desc Inserts $count columns at $col position.
	**/
	function insertColumns ( $col, $count = 1 ) {
		if( is_int( $col ) && is_int( $count ) ) {
			if( $col >= 0 && $col <= $this->numCols ) {
				for( $i = 0; $i < $this->numRows; $i++ ) {
					$temp_text = array();
					$temp_attributes = array();
					reset($this->text[ $i ]);
					for( $j = 0; $j <= $this->numCols; $j++ ) {
						if( $col == $j ) {
							for( $k = 0; $k < $count; $k++ ){
								$temp_text[] = '';
								$temp_attributes[] = array();
							}
						}
						if( $j == $this->numCols )
							break;
						$temp_text[] = $this->text[ $i ][ $j ];
						$temp_attributes[] = $this->cellsAttributes[ $i ][ $j ];
					}
					$this->text[ $i ] = $temp_text;
					$this->cellsAttributes[ $i ] = $temp_attributes;
				}
				for( $i = 0; $i < $count; $i++ )
					array_splice( $this->hiddenCols, $col, 0, FALSE );
				$this->numCols += $count;
			}
		}
	}

	/**
	* @return void
	* @param int $row
	* @desc Removes $row.
	**/
	function removeRow ( $row ) {
		if( is_int( $row ) ) {
			if( $row < $this->numRows ) {
				array_splice( $this->text, $row, 1 );
				array_splice( $this->hiddenRows, $row, 1 );
				array_splice( $this->cellsAttributes, $row, 1 );
				array_splice( $this->rowsAttributes, $row, 1 );
				$this->numRows -= 1;
			}
		}
	}

	/**
	* @return void
	* @param int $col
	* @desc Removes $col.
	**/
	function removeColumn ( $col ) {
		if( is_int( $col ) ) {
			if( $col < $this->numCols ) {
				for( $i = 0; $i < $this->numRows; $i++ ) {
					$temp_text = array();
					$temp_attributes = array();
					reset($this->text[ $i ]);
					while ( list( $key, ) = each( $this->text[ $i ] ) ) {
						if( $key != $col ) {
							$temp_text[] = $this->text[ $i ][ $key ];
							$temp_attributes[] = $this->cellsAttributes[ $i ][ $key ];
						}
					}
					$this->text[ $i ] = $temp_text;
					$this->cellsAttributes[ $i ] = $temp_attributes;
				}
				array_splice( $this->hiddenCols, $col, 1 );
				$this->numCols -= 1;
			}
		}
	}

	/**
	* @return void
	* @param int $width
	* @desc Sets Table Width.
	**/
	function setWidth ( $width ) {
		if( is_string( $width ) )
			$this->width = strval( $width );
	}

	/**
	* @return string
	* @desc Returns Table Width.
	**/
	function width () {
		return $this->width;
	}

	/**
	* @return void
	* @param int $title
	* @desc Sets Table Title.
	**/
	function setTitle ( $title ) {
		if( is_string( $title ) )
			$this->title = strval( $title );
	}

	/**
	* @return string
	* @desc Returns Table Title.
	**/
	function title () {
		return $this->title;
	}

	/**
	* @return void
	* @desc Displays the table with its cells.
	**/
	function draw () {
		if( $this->template != '' ) {
			$tpl = new $this->template;
			$tpl->__header( $this->width, $this->title );
			$this->_check_rowcol_span();
			for( $i = 0; $i < $this->numRows; $i++ ) {
				if( $this->hiddenRows[ $i ] == FALSE ) {
					$tpl->__row_start( $this->rowsAttributes[ $i ] );
					for( $j = 0; $j < $this->numCols; $j++ ) {
						if( $this->hiddenCols[ $j ] == FALSE ) {
							if( $this->text[ $i ][ $j ] !== NULL ) {
								if( is_object( $this->text[ $i ][ $j ] ) ) {
									$tpl->__cell_start( '', $this->cellsAttributes[ $i ][ $j ] );
									$this->text[ $i ][ $j ]->draw();
								}
								else 
									$tpl->__cell_start( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
								$tpl->__cell_stop( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
							}
						}
					}
					$tpl->__row_stop( $this->rowsAttributes[ $i ] );
				}
			}
			$tpl->__footer( $this->width, $this->title );
		}
	}

	// PRIVATE FUNCTIONS
	/**
	* @return void
	* @desc Sets NULL to cells if colspan or rowspan go on the cells
	**/
	function _check_rowcol_span() {
		for( $i = 0; $i < $this->numRows; $i++ ) {
			for( $j = 0; $j < $this->numCols; $j++ ) {
				if( isset( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ) )
					if( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] > 0 )
						for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ); $z++ )
							$this->text[ $i ][ $j + $z ] = NULL;
				if( isset( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ) )
					if( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] > 0 )
						for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ); $z++ )
							$this->text[ $i + $z ][ $j ] = NULL;
			}
		}
	}


	/**
	* @return void
	* @param int $r
	* @desc Sets Default Variables for row $r.
	**/
	function _setVariable ( $r ) {
		$this->text[ $r ] = array_fill( 0, $this->numCols, TABLE_DEFAULT_CELL_VALUE );
		$this->cellsAttributes[ $r ] = array_fill( 0, $this->numCols, array() );
		$this->rowsAttributes[ $r ] = array();
		$this->hiddenRows[ $r ] = TABLE_DEFAULT_ROW_HIDDEN;
	}

	/**
	* @return void
	* @param int $r
	* @desc Unsets Default Variables for row $r.
	**/
	function _unsetVariable ( $r ) {
		unset( $this->text[ $r ] );
		unset( $this->cellsAttributes[ $r ] );
		unset( $this->rowsAttributes[ $r ] );
		unset( $this->hiddenRows[ $r ] );
	}

	/**
	* @return void
	* @param string $tab
	* @desc Merge Function
	**/
	function _sort_merge ( &$tab ) {
		if( count( $tab ) <= 1 ) return;
		else {
			$tab1 = array();
			$tab2 = array();

			for( $i = 0; $i < count( $tab ); $i++) {
				if( $i < ( count( $tab ) ) / 2 )
					$tab1[] = $tab[ $i ];
				else
					$tab2[] = $tab[ $i ];
			}

			$this->_sort_merge( $tab1 );
			$this->_sort_merge( $tab2 );

			$this->_merge_all( $tab1, $tab2, $tab );
		}
	}

	/**
	* @return void
	* @param string $tab1
	* @param string $tab2
	* @param string $tab
	* @desc Merge Function
	**/
	function _merge_all ( $tab1, $tab2, &$tab ) {
		$i = 0;
		$i1 = $i2 = 0;
		while( $i1 < count( $tab1 ) && $i2 < count( $tab2 ) ) {
			if( strcmp( $tab1[ $i1 ][ $this->temp_col ], $tab2[ $i2 ][ $this->temp_col ] ) == (($this->temp_ascending==TRUE)?-1:1) )
				$tab[ $i ] = $tab1[ $i1++ ];
			else
				$tab[ $i ] = $tab2[ $i2++ ];
			$i++;
		}

		while( $i1 < count( $tab1 ) ) {
			$tab[ $i ] = $tab1[ $i1++ ];
			$i++;
		}
		while( $i2 < count( $tab2 ) ) {
			$tab[ $i ] = $tab2[ $i2++ ];
			$i++;
		}
	}
}
?>

 Conclusion

Si vous avez des questions n'hésitez pas !

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

25 août 2004 07:24:24 :
Correction Initialisation des Colonnes
25 août 2004 08:37:15 :
Ajout d'une Note pour être Compatible avec PHP4
26 août 2004 04:35:10 :
Correction de plusieurs Bugs !
23 septembre 2004 07:28:45 :
Ajout de la fonction privée _check_rowcol_span() qui permet de mieux gérer les colspan AINSI que les rowspan ! Aussi define( 'TABLE_DEFAULT_CELL_VALUE', "&nbsp" ); permet de définir que vaut la cellule lorsqu'elle n'est pas définie... Si NULL, la cellule n'est pas écrite.
23 septembre 2004 07:42:46 :
Le ZIP ne s'est pas envoyé... grrr !
09 décembre 2004 08:46:45 :
Correction de ; à &nbsp; + correction des templates pour fonctionner aux standards XML + utilisation des apostrophes (') plutôt que des guillemets (") pour une amélioration de la performance.
05 janvier 2005 17:56:24 :
Correction bug de récursivité setText() (v1.05)

 Sources du même auteur

Source avec Zip Source avec une capture LECTURE/ÉCRITURE DE TAGS ID3 VERSION 1 ET VERSION 2
Source avec Zip GÉRER LES ÉCHAPPEMENTS DE CARACTÈRES SUR TABLEAUX MULTIDIMEN...
Source avec Zip Source avec une capture PROJECT SELECTOR (SÉLECTION FACILE DE PROJET AVEC APACHE) ET...
Source avec Zip Source avec une capture STATISTIQUES DE VOTRE PROJET (NOMBRE DE DOSSIERS, FICHIERS, ...
Source avec Zip TRI FUSION - MERGESORT

 Sources de la même categorie

Source avec une capture MODULE JOOMLA 1.5 NOW LISTENING par Alcantornet
Source avec Zip Source avec une capture UPLOAD CENTER par basssem81
Source avec Zip COMPTEUR DE CLIQUE PHP AVEC JQUERY par devgoneti
Source avec Zip LIVRE D'OR SIMPLE (POUR DÉBUTANT) par devgoneti
Source avec Zip SCRIPT TRAVAUX POUR VOTRE SITE par FleuryK

Commentaires et avis

Commentaire de bprod le 30/08/2004 09:48:28

Merci pour ce beau taff, je n'ai pas eu le temps de tester
mais je regarderais ça en détail d'ici peu...

Commentaire de Anthomicro le 31/08/2004 19:32:36

Salut ;-)

Tous tes :
- while( $i1 < count( $tab1 )
- while( $i1 < count( $tab1 ) )
- while( $i2 < count( $tab2 ) )

ne sont pas optimisés. Il faut stocker la valeur count($tableau) dans une variable sinon elle est recalculée à chaque fois :

$ci1=count($tab1);
while($i1<$ci1)
{
  traitement
}

a ++

Commentaire de GRenard le 31/08/2004 20:55:34

Merci du commentaire... j'updaterai lorsque j'aurai le temps, mais disons que c'est rare que je fais ça (pas updater, mais ske tu as dit :P)... Car la vitesse ici serait TRÈS peu différente.

Commentaire de Anthomicro le 31/08/2004 22:16:34

Tout dépend de la longueur de ta boucle, et puis du "très peu" + "très peu" + "très peu", ça fait beaucoup mdr !

A ++

Commentaire de GRenard le 23/09/2004 07:32:40

Mise à jour du script. Version 1.03 !

Commentaire de GRenard le 05/01/2005 17:58:01

Mise à jour du script. Version 1.05 !

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,484 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales