我用谷歌搜索并尝试了几件事都无济于事。我正在学习 PHP 和 MySQL 中的一些课程,并尝试为数组结果中的行添加交替颜色。到目前为止,没有任何效果。我不知道该放在哪里。这是我的代码:
//assemble the sql query string to insert a record
$query="SELECT * FROM Vehicles WHERE buyer IS NOT NULL ORDER BY StockID asc";
//open a connection and select the database
$conn=mysql_connect($host, $username, $password);
@mysql_select_db($database, $conn) or die ("Unable to select $database database");
//Execute the sql query
if($result=mysql_query($query, $conn)){
$rows=mysql_numrows($result);
echo"<p>There are $rows cars in the system</p>";
?>
<table border="0" align="center" border="0" cellspacing="0" style="margin:auto; border-spacing:2px 1px; border-collapse:separate; border:ridge 5px; border-color:#669999;">
<tr>
<td style="background-color:#92DEDC">Stock ID</td>
<td style="background-color:#92DEDC">Reg Number</td>
<td style="background-color:#92DEDC">Make</td>
<td style="background-color:#92DEDC">Model</td>
<td style="background-color:#92DEDC">Year</td>
<td style="background-color:#92DEDC">Cost Price</td>
<td style="background-color:#92DEDC">EmpID</td>
<td style="background-color:#92DEDC">Sell Price</td>
<td style="background-color:#92DEDC">Seller</td>
<td style="background-color:#92DEDC">Buyer</td>
<td style="background-color:#92DEDC">Admin Tasks</td>
</tr>
<?php
$i=0;
while($i<$rows){
$recordArray=mysql_fetch_array($result);//fetch and display a record
echo "<tr bgcolor='$bgcolor'>
<td >$recordArray[StockID]</td>
<td>$recordArray[Rego_No]</td>
<td>$recordArray[Make]</td>
<td>$recordArray[Model]</td>
<td>$recordArray[Year]</td>
<td>$recordArray[Cost_Price]</td>
<td>$recordArray[employeeid]</td>
<td>$recordArray[Sale_Price]</td>
<td>$recordArray[emp_name]</td>
<td>$recordArray[Buyer]</td>
<td>
<a href='edit-car.php?StockID=$recordArray[StockID] & emp_name=$recordArray[emp_name]'>Edit</a>
</td>
</tr>";
$i++;
}else{
echo "Something went wrong. MySQL reports <b>", mysql_error(),"</b>";
}
?>
</table>
<?php
mysql_close($conn);
?>
</body></html>
任何帮助将不胜感激。我们只有一周的课程,我只是想稍微修饰一下结果。