Array weergave
vak429 - 08/08/2005 23:33
Nieuw lid
in deze html tabel kleurt de backgroundcolor van de tr's telkens andersom maar nu wil ik ook graag dat de kleur van het lettertype anders kleurt zit al tijden te pielen maar ik zie t zo ff niet...:
<html>
<body>
<table width="541" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="C31E1E">
<td width="44"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Positie</font></td>
<td width="121"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Club</font></td>
<td width="43"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Gespeeld</font></td>
<td width="45"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Winst</font></td>
<td width="50"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Gelijk</font></td>
<td width="48"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Verlies</font></td>
<td width="52"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Punten</font></td>
<td width="64"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Goals voor </font></td>
<td width="74"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Goals tegen </font></td>
</tr>
<?
$t = 1;
// loop door $row welke een array is met alle resultaten van de query
while ($row = mysql_fetch_array($res))
{
if (isset($color) && ($color == "#ffffff")) { $color = "#C31E1E"; $font = "size='1' face='Verdana, Arial, Helvetica, sans-serif' color='#FFFFFF'";} else{ $color = "#ffffff"; $font = "size='1' face='Verdana, Arial, Helvetica, sans-serif' color='#FF0000'"; }?>
<tr style="background:<?=$color?>" style="font: ">
<td> <div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $t ?></font></div></td>
<td fom><? echo $row['clubnaam'] ?></font></td>
<td> <div align="center"><? echo $row['gespeeld'] ?></font></div></td>
<td> <div align="center"><? echo $row['gewonnen'] ?></font></div></td>
<td> <div align="center"><? echo $row['gelijk']?></font></div></td>
<td> <div align="center"><? echo $row['verloren']?></font></div></td>
<td> <div align="center"><? echo $row['punten']?></font></div></td>
<td> <div align="center"><? echo $row['doelvoor']?></font></div></td>
<td> <div align="center"><? echo $row['doeltegen']?></font></div></td>
</tr>
<? $t++; }
?></table>
</body></html>
<html>
<body>
<table width="541" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="C31E1E">
<td width="44"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Positie</font></td>
<td width="121"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Club</font></td>
<td width="43"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Gespeeld</font></td>
<td width="45"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Winst</font></td>
<td width="50"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Gelijk</font></td>
<td width="48"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Verlies</font></td>
<td width="52"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Punten</font></td>
<td width="64"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Goals voor </font></td>
<td width="74"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Goals tegen </font></td>
</tr>
<?
$t = 1 ;
// loop door $row welke een array is met alle resultaten van de query
{
if ( isset ( $color ) && ( $color == "#ffffff" ) ) { $color = "#C31E1E" ; $font = "size='1' face='Verdana, Arial, Helvetica, sans-serif' color='#FFFFFF'" ; } else { $color = "#ffffff" ; $font = "size='1' face='Verdana, Arial, Helvetica, sans-serif' color='#FF0000'" ; } ?> <tr style="background:<?= $color ?> " style="font: ">
<td> <div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
<? echo $t ?> </font></div></td>
<td fom>
<? echo $row [ 'clubnaam' ] ?> </font></td>
<td> <div align="center">
<? echo $row [ 'gespeeld' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'gewonnen' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'gelijk' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'verloren' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'punten' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'doelvoor' ] ?> </font></div></td>
<td> <div align="center">
<? echo $row [ 'doeltegen' ] ?> </font></div></td>
</tr>
<? $t ++; }
?> </table>
</body></html>
4 antwoorden
Gesponsorde links
vak429 - 08/08/2005 23:41
Nieuw lid
???
nemesiskoen - 08/08/2005 23:44
PHP expert
btway, kan je nog wat lelijker scripten?
gooi dat is door W3?
Je sluit tig keer je font tag en opent hem amper 1 maal
<tr style="background:<?=$color?>" style="font: ">
<td> <div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $t ?></font></div></td>
<td fom><? echo $row['clubnaam'] ?></font></td>
<td> <div align="center"><?php echo "<font ".$font.">";
echo $row['gespeeld'] ?></font></div></td>
<tr style="background:<?= $color ?> " style="font: ">
<td> <div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
<? echo $t ?> </font></div></td>
<td fom>
<? echo $row [ 'clubnaam' ] ?> </font></td>
<td> <div align="center">
<?php echo "<font " . $font . ">" ; echo $row [ 'gespeeld' ] ?> </font></div></td>
etc...
lijn eens uit en maak gebruik van tabs aub... dit valt echt niet te lezen.
DRUNK - 09/08/2005 00:17 (laatste wijziging 09/08/2005 00:18)
PHP gevorderde
Probeer deze functie, voorbeeld van gebruik zit ook in de onderstaande code. Voorbeeld zie: http://www.http-error.nl/rows.php /
<?php error_reporting(E_ALL);
define ("NL", "\n");
define ("T", "\t");
$rows = array(1,2,3,4,5,6,7,8,9,0);
$font = array('even' => '0000ff', 'oneven' =>'ff0000');
$bg = array('even' => 'ff0000', 'oneven' =>'0000ff');
function fill_rows($num, &$font_color, &$row_color) {
global $font, $bg;
if ($num & 1) {
$font_color = $font['even'];
$row_color = $bg['even'];
}
else {
$font_color = $font['oneven'];
$row_color = $bg['oneven'];
}
return TRUE;
}
$html = '<table width="50%" align="center">'.NL.T.'<tr>';
for ($i = 0, $max = sizeof($rows); $i < $max; $i++) {
fill_rows($i, $font_color, $row_color);
$html .= NL.T.T.'<td align="center" bgcolor="'.$row_color.'"><font color="'.$font_color.'">'.$rows[$i].'</font></td>';
}
$html .= NL.T.'</tr>'.NL.'</table>';
print $html;
?>
$rows = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 ) ; $font = array ( 'even' => '0000ff' , 'oneven' => 'ff0000' ) ; $bg = array ( 'even' => 'ff0000' , 'oneven' => '0000ff' ) ;
function fill_rows( $num , & $font_color , & $row_color ) {
if ( $num & 1 ) {
$font_color = $font [ 'even' ] ;
$row_color = $bg [ 'even' ] ;
}
else {
$font_color = $font [ 'oneven' ] ;
$row_color = $bg [ 'oneven' ] ;
}
return TRUE ;
}
$html = '<table width="50%" align="center">' . NL. T. '<tr>' ;
for ( $i = 0 , $max = sizeof ( $rows ) ; $i < $max ; $i ++ ) { fill_rows( $i , $font_color , $row_color ) ;
$html .= NL. T. T. '<td align="center" bgcolor="' . $row_color . '"><font color="' . $font_color . '">' . $rows [ $i ] . '</font></td>' ;
}
$html .= NL. T. '</tr>' . NL. '</table>' ;
?>
Gesponsorde links
Dit onderwerp is gesloten .