表格背景顏色 表格背景顏色

 

<html>
<head><title>查詢資料表的記錄資料</title>
<meta name="viewport" content="width=device-width, initial-scale=1">  <!-- 配合手機視窗 -->
</head>
<body>
<table border=1>
<?
$i = 0;
$link = mysqli_connect("localhost","10079505",
                       "10079505","10079505");
  
$sql = "SELECT * FROM jqm_products";
if ( $result = mysqli_query($link, $sql) ) { 
 
   while( $row = mysqli_fetch_assoc($result) ){
if ( $i == 0){
echo "<td bgcolor = #FF0000>".$row["name"]."</td>". "<td bgcolor = #FF0000>".$row["price"]."</td>"."<tr>";
$i++;
}
else{
echo "<td bgcolor = #0000FF>".$row["name"]."</td>". "<td bgcolor = #0000FF>".$row["price"]."</td>"."<tr>";
$i--;
}
}
   mysqli_free_result($result); 
}
mysqli_close($link);  
?>
</table>
</body>
</html>