作業一 作業一

 <!-- 程式範例:Ch13-3-1.php -->

<html>
<head><title>查詢資料表的記錄資料</title></head>
<body>
<table border=1>
<?
 
$link = mysqli_connect("localhost","10079517",
                       "10079517","10079517");
        
$sql = "SELECT * FROM jqm_products";
 
if ( $result = mysqli_query($link, $sql) ) { 
   
   while( $row = mysqli_fetch_assoc($result) ){ 
      echo "<td>".$row["name"]."</td>". "<td>".$row["price"]."</td>"."<tr>";
   } 
  
   mysqli_free_result($result); 
mysqli_close($link);  
?>
</table>
</body>
</html>
作業二 作業二

<!-- 程式範例:Ch13-3-1.php -->

<html>

<head><title>查詢資料表的記錄資料</title>

<meta charset="utf-8"/>

</head>

<body>

 

<table border=1>

<?

 

$color[0] = "#F4BBBA";

$color[1] = "#D8BAF4";

$i=0;

 

$link = mysqli_connect("localhost","10079517",

                       "10079517","10079517");

        

$sql = "SELECT * FROM jqm_products";

 

if ( $result = mysqli_query($link, $sql) ) { 

   

while( $row = mysqli_fetch_assoc($result) ){ 

if ($i==0) {  

echo "<td bgcolor=".$color[0].">".$row["name"]."</td>". "<td bgcolor=".$color[0].">".$row["price"]."</td>"."<tr>";

            $i=1;

} else {

echo "<td bgcolor=".$color[1].">".$row["name"]."</td>". "<td bgcolor=".$color[1].">".$row["price"]."</td>"."<tr>";

            $i=0;

}

   } 

  

   mysqli_free_result($result); 

mysqli_close($link);  

?>

</table>

</div>

 

</body>

</html>