我正在创建一个混合的html php文档,在while循环中,我正在将MySQL数据库的内容列出到一个表中。由于需要转义以下字符,我在使用echo命令时遇到了麻烦:'“ /也许= 我确定某些事情也需要串联
问题出在我的while循环中,这是完整的代码,如果有帮助的话。
<!doctype html> <!-- Author: MPPR -->
<html lang="en"><!-- Date: Oct 26,2018 -->
<head> <!-- Description: Products page -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Products</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="wrapper">
<header>
<h1>Products: MPPR Sales</h1>
</header>
<nav>
<ul>
<li class="home"><a href="index.html">Home</a></li>
<li class="products"><a href="products.html.php">Products</a></li>
<li class="about"><a href="about.html">About</a></li>
<li class="contact"><a href="contact.html">Contact</a></li>
</ul>
</nav>
</div>
<article>
<table>
<thead>
<tr>
<th>Image</th>
<th>Item#</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
$servername = "127.0.0.1";
$username = "obmitted";
$password = "obmitted";
$dbname = "obmitted";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT item_number, item_description, unit_price, quantity,
unit_price, image FROM catalog";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td class= /"prodimage/"> <img src= /"images/$row[/'image/']/" width=/"100/" height= /"120/"></td>";
}
} else {
echo "<tr><td>0 results<td></tr>";
}
echo "</tbody></table>";
mysqli_close($conn);
?>
</article>
<footer>
<p>© <span id="year">2018</span> copyright: MPPR Sales.</p>
</footer>
</body>
</html>