Accueil > > > SIMPLE TABLE FUNCTION
SIMPLE TABLE FUNCTION
Information sur la source
Description
Petite fonction simple sans pretention.... On lui passe 2 arrays (1 pour les entetes et 1 autre pour les data) avec en option le nom d'un style pour l'entete et pour la table elle-meme... la fonction n'affice rien mais renvoi un tableau qu'il suffit ensuite d'imprimer.
Source
- <style>
- TABLE.smtTable{
- border-left:1px black solid;
- border-right:1px solid black;
- border-bottom:1px solid black;
- border-top:1px solid black;
- margin-right:15px;
- width:800px;
- font-size:11pt;
- }
-
- TR.smtRowOdd{
-
- background-color:lightgrey;
- }
- TR.smtRowEven{
- background-color:white;
- }
- TR.smtHeader{
- background-color:#2d1663;
- background-color:#F0F0F0;
- color:#2d1663;
- font-weight:bold;
- font-size:13pt;
- }
- </style>
-
-
-
- <?php
-
-
-
- function DisplayTable($tablehead,$tabledata,$styletable='smtTable',$stylehead='smtHeader')
- {
-
- //Creating HTML table
- $table='<table class=' . $styletable .'>'."\n";
- $table.='<tr class=' . $stylehead . '>' . "\n";
-
- //now displaying table head
- $col=count($tablehead);
-
- //Looping inside tableheaders and displaying them
- foreach ($tablehead as $t)
- {
- if (empty($t)) {$t='_';}$table.='<td>' .$t.'</td>'."\n";
- }
- $table.='</tr>'."\n";
-
-
- //now displaying data with row colors
- $numel=count($tabledata); //amount of cells
- $rows=intval($numel/$col); // line count is cells/col
- $pointeur=0; //pointeur for data
- //first loop, we are going through each row, row length is based on number of Header element
- for ($i=0;$i<$rows;$i++)
- {
- //changing row color. Using modulo function (always returns 1 or 0)
- if ($i%2 == 0) $s="smtRowEven"; else $s="smtRowOdd";
- $table.='<tr class=' . $s . '>' . "\n";
- //We display each cells in the row. Number of Colums is based on number of header as set above
- for ($j=0;$j<$col;$j++)
- {
- $d=$tabledata[$pointeur];
-
- if (empty($d)) {$d='_';}$table.='<td >' . $d . '</td>' . "\n";
- $pointeur++; // moving to next element on tableset
- }
- $table.='</tr>'."\n";
- }
- $table.='</table>'."\n";
- return $table;
- }
-
- $head=array("head1","head2","head3","test1");
- $data=array("r1d1","r1d2","r2d1","r2d2","r3d1","r3d2","r2d2","r3d1","r3d2");
- $d=DisplayTable($head,$data);
- print $d;
- print "done";
-
- ?>
<style>
TABLE.smtTable{
border-left:1px black solid;
border-right:1px solid black;
border-bottom:1px solid black;
border-top:1px solid black;
margin-right:15px;
width:800px;
font-size:11pt;
}
TR.smtRowOdd{
background-color:lightgrey;
}
TR.smtRowEven{
background-color:white;
}
TR.smtHeader{
background-color:#2d1663;
background-color:#F0F0F0;
color:#2d1663;
font-weight:bold;
font-size:13pt;
}
</style>
<?php
function DisplayTable($tablehead,$tabledata,$styletable='smtTable',$stylehead='smtHeader')
{
//Creating HTML table
$table='<table class=' . $styletable .'>'."\n";
$table.='<tr class=' . $stylehead . '>' . "\n";
//now displaying table head
$col=count($tablehead);
//Looping inside tableheaders and displaying them
foreach ($tablehead as $t)
{
if (empty($t)) {$t='_';}$table.='<td>' .$t.'</td>'."\n";
}
$table.='</tr>'."\n";
//now displaying data with row colors
$numel=count($tabledata); //amount of cells
$rows=intval($numel/$col); // line count is cells/col
$pointeur=0; //pointeur for data
//first loop, we are going through each row, row length is based on number of Header element
for ($i=0;$i<$rows;$i++)
{
//changing row color. Using modulo function (always returns 1 or 0)
if ($i%2 == 0) $s="smtRowEven"; else $s="smtRowOdd";
$table.='<tr class=' . $s . '>' . "\n";
//We display each cells in the row. Number of Colums is based on number of header as set above
for ($j=0;$j<$col;$j++)
{
$d=$tabledata[$pointeur];
if (empty($d)) {$d='_';}$table.='<td >' . $d . '</td>' . "\n";
$pointeur++; // moving to next element on tableset
}
$table.='</tr>'."\n";
}
$table.='</table>'."\n";
return $table;
}
$head=array("head1","head2","head3","test1");
$data=array("r1d1","r1d2","r2d1","r2d2","r3d1","r3d2","r2d2","r3d1","r3d2");
$d=DisplayTable($head,$data);
print $d;
print "done";
?>
Conclusion
J'ais cree ce code car j'avais besoin d'une petite fonction me permettant d'afficher simplement un tableau sans fioriture (essentiellement 1 ou 2 lignes)... Suggestion/amelioration sont bien entendu les bienvenues ...
Historique
- 12 avril 2005 14:29:50 :
- Mise a jour du code avec les suggestions ... merci pour les commentaires...
- 12 avril 2005 14:38:24 :
- Mise a jour du code avec les suggestions ... merci pour les commentaires...
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WF4] PASSAGE D'ARGUMENTS LITERAL, VISUALBASICVALUE OU LAMBDAVALUE?[WF4] PASSAGE D'ARGUMENTS LITERAL, VISUALBASICVALUE OU LAMBDAVALUE? par JeremyJeanson
Avec la sortie de la RC de Visual Studio 2010, Microsoft a mis un peu les points sur leS i en ce qui concernait le passage d'arguments. Mais nous somme un certain nombre à avoir pris ce changement comme un coup dur. Pour résumer la situation : à la sortie...
Cliquez pour lire la suite de l'article par JeremyJeanson [RIA SERVICES] INCLUDE ET DOMAINDATASOURCE[RIA SERVICES] INCLUDE ET DOMAINDATASOURCE par Audrey
Dans un de mes articles précédents , j'avais parlé des DomainDataSource avec RIA Services dans le cas d'une interface Maître - Détail. Dans le même principe, je vais parler d'une autre manière de mettre en forme ce cas d'interface avec RIA Services. Et po...
Cliquez pour lire la suite de l'article par Audrey ZUNE : VERSION ZUNE SOFTWARE V 4.2 ET LA SOCIALISATIONZUNE : VERSION ZUNE SOFTWARE V 4.2 ET LA SOCIALISATION par ROMELARD Fabrice
Une des nouveautés de la version V 3.0 était l'apparition de l'onglet Social qui ne fonctionnait que si le MarketPlace était activé sur son poste. Cela limitait donc son intérêt, car hors du cadre commercial USA-CANADA, peu de monde trouva...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PRATIQUE DE SILVERLIGHT PAR ERIC AMBROSIPRATIQUE DE SILVERLIGHT PAR ERIC AMBROSI par MPOWARE
Je viens de finir la lecture du dernier livre d'
Eric Ambrosi
éditions PEARSON
Son livre donne une approche pratique de Silverlight qui sera aussi bien comprise par le développeur que par le designeur.
Tous les aspects du développement RIA sont abor...
Cliquez pour lire la suite de l'article par MPOWARE APPRENDRE à DéVELOPPER POUR LES MOBILES AVEC LA NOUVELLE GéNéRATION .NETAPPRENDRE à DéVELOPPER POUR LES MOBILES AVEC LA NOUVELLE GéNéRATION .NET par odewit
2 déclinaisons de Silverlight et 2 déclinaisons de Mono permettent dorénavant (ou permettront prochainement) de développer des applications .NET mobiles pour les principales plates-formes du marché :
Silverlight pour Symbian, basé sur Silverlight 2...
Cliquez pour lire la suite de l'article par odewit
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|