【发布时间】:2018-04-09 22:33:20
【问题描述】:
我的数据库“enchere”中有一个名为 Produit 的表。
我想显示存储在表 produit 中的数据。这些数据是 Nom_produit、description_produit 和产品图片。
图像存储在服务器中(在我的机器中,我正在使用 Xampp 测试我的代码)。
我得到所有数据并显示出来。问题是图像无法显示。我试图确保图像的 URL 输入正确,但我无法修复问题。请提供任何帮助 附上我的网页截图,没有显示图像 下面是我的代码。
$conn=new mysqli('localhost','root','','enchere');
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "select * from produit ";
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
//$row = mysqli_fetch_array($query);
//echo "127.0.0.1/images/".$row['image'];
?>
<html>
<head>
<title>Displaying MySQL Data in HTML Table</title>
<style type="text/css">
body {
font-size: 15px;
color: #343d44;
font-family: "segoe-ui", "open-sans", tahoma, arial;
padding: 0;
margin: 0;
}
table {
margin: auto;
font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
font-size: 12px;
}
h1 {
margin: 25px auto 0;
text-align: center;
text-transform: uppercase;
font-size: 17px;
}
table td {
transition: all .5s;
}
/* Table */
.data-table {
border-collapse: collapse;
font-size: 14px;
min-width: 537px;
}
.data-table th,
.data-table td {
border: 1px solid #e1edff;
padding: 7px 17px;
}
.data-table caption {
margin: 7px;
}
/* Table Header */
.data-table thead th {
background-color: #508abb;
color: #FFFFFF;
border-color: #6ea1cc !important;
text-transform: uppercase;
}
/* Table Body */
.data-table tbody td {
color: #353535;
}
.data-table tbody td:first-child,
.data-table tbody td:nth-child(4),
.data-table tbody td:last-child {
text-align: right;
}
.data-table tbody tr:nth-child(odd) td {
background-color: #f4fbff;
}
.data-table tbody tr:hover td {
background-color: #ffffa2;
border-color: #ffff0f;
}
/* Table Footer */
.data-table tfoot th {
background-color: #e5f5ff;
text-align: right;
}
.data-table tfoot th:first-child {
text-align: left;
}
.data-table tbody td:empty
{
background-color: #ffcccc;
}
</style>
</head>
<body>
<h1>VALIDATION DES PRODUITS AJOUTES</h1>
<table class="data-table">
<caption class="title">Produit en attente Validation administrateur</caption>
<thead>
<tr>
<th>Nom_Produit</th>
<th>Description_Produit</th>
<th>Prix_Produit</th>
<th>Image_Produit</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($query))
{
//$amount = $row['amount'] == 0 ? '' : number_format($row['amount']);
echo '<tr>
<td>'.$row['nom'].'</td>
<td>'.$row['description'].'</td>
<td>'.$row['prix'].'</td>
<td>'.'<img src='."127.0.0.1/images/".$row['image']." width=100 height=100";'/></td>
</tr>';
}?>
</tbody>
</table>
</body>
</html>
【问题讨论】:
-
"我得到所有数据并显示。问题是图像无法显示"数据库中的图像链接是否正确?图像的位置是否正确?这个输出
var_dump($row['image']);是什么?表格中是否存在“图像”字段? -
OP 在这里搞乱了连接...如您所见,他在单引号和双引号之间切换,因此最后一个
单元格存在问题...此外,图片链接不是相对的。 '.' -
我要感谢你们所有人 :) :) 它有效