【发布时间】:2018-06-23 20:00:38
【问题描述】:
我有一个网页,显示从表格中的第一辆车到最后一辆车的汽车,并带有一个 while 循环。
我有以下列:品牌、型号、价格。在我的语法中,我在 Make 行周围有一个锚标记,链接到 Make you click on 的描述页面。
我希望我的<h> 标签更改为相应品牌的型号。
我已经花了一个多小时试图实现这一目标,但我能想到的是:
<?php
$query = "SELECT Model FROM inventory;";
$Vtitle = $conn->query($query);
$Vtitle_ar = mysqli_fetch_assoc($Vtitle);
echo "<h1>".$Vtitle_ar['Model']."</h1>";
?>
这在一定程度上有效。
我单击的每个锚点都会将<h> 标记替换为数据库中模型列下的第一个结果。
这是整个汽车库存页面的代码
<?php
$query = "SELECT * FROM inventory;";
/* Try to query the database */
if ($result = $conn->query($query)) {
// Don't do anything if successful.
}
else {
echo "Error getting cars from database:" .$conn->error()."<br>";
}
// Create the table headers
echo "<table id='Grid' style='width: 80%'><tr>";
echo "<th style='width: 50px'>Make</th>";
echo "<th style='width: 50px'>Model</th>";
echo "<th style='width: 50px'>Asking Price</th>";
echo "</tr>\n";
$class = "odd"; // keep track of whether a row was even or odd, so we can style it later
// Loop through all the rows returned by the query, creating a table for each row
while ($result_ar = mysqli_fetch_assoc($result)) {
echo "<tr class=\"$class\">";
echo "<td><a href='viewcar.php?VIN=".$result_ar['VIN']."'>".$result_ar['Make']."<a></td>";
echo "<td>".$result_ar['Model']."</td>";
echo "<td>".$result_ar['ASKING_PRICE']."</td>";
echo "</td></tr>\n";
// if the last row was even, make the next one odd and vice-versa
if ($class=="odd") {
$class = "even";
}
else {
$class = "odd";
}
}
echo "</table>";
$conn->close();
?>
有谁可以做到这一点?
我是编程新手,我正在尝试将它用于我正在为美发沙龙网站工作的实际项目
【问题讨论】:
-
SELECT Model FROM inventory WHERE VIN=YOUR_VALUE
标签: php html mysql select while-loop