<!-- 程式範例:Ch13-5-1.php -->
<html>
<head><title>讀取單筆記錄的索引陣列</title></head>
<body>
<?
$names[] = "#66FF66";
$names[] = "#FFFF77";
$flag=0;
$link = mysqli_connect("localhost","10179524",
"10179524","test");
$sql = "SELECT * FROM jqm_products,jqm_category where category=c_id";
$result = mysqli_query($link, $sql);
echo "<table border=0><tr>";
while ( $meta = mysqli_fetch_field($result) )
echo "<td bgcolor=\"#9999FF\">".$meta->name."</td>";
echo "</tr>";
$total_fields = mysqli_num_fields($result);
echo $total_fields;
while ($row = mysqli_fetch_row($result)) {
echo "<tr>";
if ($flag==0)
{
for ( $i = 0; $i <= $total_fields-1; $i++ )
echo "<td bgcolor=".$names[0].">" . $row[$i] . "</td>";
$flag=1;
}
else
{
for ( $i = 0; $i <= $total_fields-1; $i++ )
echo "<td bgcolor=".$names[1].">" . $row[$i] . "</td>";
$flag=0;
}
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
mysqli_close($link);
?>
</body>
</html>