|
|
|
แสดงข้อมูลสลับสีระหว่างแถว อยากทราบวิธีการดึงข้อมูลจากฐานข้อมูลมาแสดงและให้มีการแสดงสีสลับกัน |
|
|
|
|
|
|
|
<?
$sql1 = "select * from tbl ";
$exe1 = odbc_exec($connect,$sql1);
$a=1;
while(odbc_fetch_row($exe1,$a)){
if ($a % 2){
echo "<table width='500' border='0' cellpadding='1' cellspacing='0' bordercolor='#CCCCCC' bgcolor='#FFFFFF'>";
}else{ echo "<table width='500' border='0' cellpadding='1' cellspacing='0' bordercolor='#CCCCCC' bgcolor='#F0F0F0'>"; }
echo"<tr>";
echo "<td width='99'><div align='center'><font size='1' face='Tahoma, MS Sans Serif, MS Dialog Light'> $htime </font></div></td>";
echo "<td width='101'><div align='center'><font size='1' face='Tahoma, MS Sans Serif, MS Dialog Light'> $husr </font></div></td>";
echo "<td width='125'><div align='center'><font size='1' face='Tahoma, MS Sans Serif, MS Dialog Light'> $hchange </font></div></td>";
echo "<td width='152'><div align='center'><font size='1' face='Tahoma, MS Sans Serif, MS Dialog Light'> $hdescription </font></div></td>";
echo"</tr>";
echo "</table>";
$a++;
}
?>
apply ดูนะครับ
|
|
|
|
|
Date :
10 ก.ย. 2550 14:43:32 |
By :
tik |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
if($i%2==0)
{
$bg = "#CCCCCC";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
|
|
|
|
|
Date :
2009-05-28 18:35:08 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|