这是我构建的代码, 请帮我修改我的代码。
$table="<tr>
<td>Book Title</td>
<td>Quantity</td>
</tr>";
$query = "select * from book";
$result = mysql_query($query);
while($row = mysql_fetch_array($query)){
$table.="<tr>
<td>{$row['title']}</td>
<td>{$row['quantity']}</td>
</tr>";
}
$table="<table border>$table</table>";
echo $table;
答案 0 :(得分:0)
不推荐使用Mysql,但这是另一个主题。
您可以在查询中获取具有相同标题的图书数量:
$table="<tr>
<td>Book Title</td>
<td>Quantity</td>
</tr>";
$query = "SELECT b.title, (SELECT COUNT(bc.title FROM book AS bc WHERE b.title=bc.title) AS quantity FROM book AS b";
$result = mysql_query($query);
while($row = mysql_fetch_array($query)){
$table.="<tr>
<td>{$row['title']}</td>
<td>{$row['quantity']}</td>
</tr>";
}
$table="<table border>$table</table>";
echo $table;