1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<?php
$connec=mssql_connect("server", "usr", "mdp");
$sel=mssql_select_db("RESSOURCE", $connec);
$sql = "
SELECT NOM
FROM USER_tbl
" ;
$result = mssql_query ( $sql, $connec) ;
//<!-- -------------------------------------corps----------------------------------------------------- -->
$html = '<table border="1" width="600" cellspacing="0" cellpadding="0" align="center">' ;
$i = 0 ;
while ( $row = mssql_fetch_assoc ( $result ) )
{
if ( $i == 0 )
{
$html .= '<tr>' ;
}
$html .= '<td width="300">' . htmlspecialchars ( $row['NOM'] ) . '</td>' ;
$i++ ;
if ( ( $i % 2 ) == 0 )
{
$html .= '</tr>' ;
$i = 0 ;
}
}
$html .= '</table>' ;
//<!-- -------------------------------------corps----------------------------------------------------- -->
function affiche_tab ( $tab , $nb )
{
$nb_var = count ( $tab ) ; // nombre d'occurence à afficher
$nb_line = ceil ( count ( $tab ) / $nb ) ; // nombre de ligne que comportera le tableau HTML
$nb_cell = $nb_line * $nb - $nb_var ; // nombre de cellule "vide" à la fin du tableau HTML
$width = ceil ( 100 / $nb ) ; // largeur des cellules en %
$table_html = '<table border="1" width="600" cellspacing="0" cellpadding="0" align="center">' ; // A personnaliser
$i = 0 ;
foreach ( $tab as $value )
{
if ( $i == 0 ) // Début d'une ligne de tableau HTML
{
$table_html .= '<tr>' ;
}
$table_html .= '<td width="' . $width . '%">' . $value . '</td>' ;
$i ++ ;
if ( $i == $nb ) // Fin d'une ligne de tableau HTML
{
$table_html .= '</tr>' ;
$i = 0 ;
}
}
$end_table_html = '' ;
if ( $nb_cell != 0 )// Ajout de cellule "vide" pour finir le tableau HTML
{
$i = 0 ;
while ( $i <$nb_cell )
{
$end_table_html .= '<td> </td>' ;
$i ++ ;
}
$end_table_html .= '</tr>' ;
}
$table_html .= $end_table_html . '</table>' ;
return $table_html ;
}
$tab = array() ;
while ( $row = mssql_fetch_assoc ( $result ) )
{
$tab[] = $row['name'] ;
}
//<!-- -------------------------------------corps----------------------------------------------------- -->
echo affiche_tab ( $row , 2 ) ;
//<!-- -------------------------------------corps----------------------------------------------------- -->
?> |
Partager