回显表中从 SQL 数据库引用的所有图像目标文件夹



这就是我所拥有的,但看不到为什么只显示一张图像而表格的其余部分被破坏

echo "<table id='customers'>"; // start a table tag in the HTML
while($row = $result->fetch_assoc()) {
echo "<tr><th><b>Logo:</b></th>
<th><b>Details: </b></th>
<th><b>id: </b></th>
<th><b>Support: </b></th>
<th><b>Amount: </b></th>
<th><b>Paid: </b></th>
<th><b>Created: </b></th></tr>
<tr><th><img src=/images/" . $row["image"]. " " . "style='width:128px; height:128px'/></th>
<th>" . $row["image_text"]. " " . "</th>
<th>" . $row["id"]. " " . "</th>
<th>" . $row["support"]. " " . "</th>
<th>" . $row["Amount"]. " " . "</th>
<th>" . $row["Paid"]. " " . "</th>
<th>" . $row["created"]."</th></tr><br>";

回显 ";关闭 HTML 中的表

页面在这里

正如 yeti 的回答中所建议的那样,您有一些缺少引号,但查看该页面的源代码,您会在 while 循环的每次迭代中包含</table>。尝试这样的事情:

// Open the table here
echo "<table id='customers'>";
while($row = $result->fetch_assoc()) {
// Now loop through each element
echo '<tr><th><b>Logo:</b></th>
<th><b>Details:</b></th>
<th><b>id:</b></th>
<th><b>Support:</b></th>
<th><b>Amount:</b></th>
<th><b>Paid:</b></th>
<th><b>Created:</b></th></tr>
<tr><td><img src="/images/' .$row["image"]. '" style="width:128px; height:128px;"/></td>
<td>'.$row["image_text"].'</td>
<td>'.$row["id"].'</td>
<td>'.$row["support"].'</td>
<td>'.$row["Amount"].'</td>
<td>'.$row["Paid"].'</td>
<td>'.$row["created"].'</td></tr><br>';
}
// Close the table after the loop is complete
echo '</table>';

注意:您会看到我移动了您的一些th标签。您正在使用通常为表标题保留的th标签来输出数据。我会将您的数据项移动到td标签中。有关表结构的更多信息,请参阅此处。

如果您看到页面的 html 代码,则结果如下:

…
<img src=/images/13_streamspinner.png style='width:128px; height:128px'/>
…

看来你一直在混淆引号。你忘记了一些提示。

试试这个:

echo "<table id='customers'>"; // start a table tag in the HTML
while($row = $result->fetch_assoc()) {
echo '<tr><th><b>Logo:</b></th>
<th><b>Details:</b></th>
<th><b>id:</b></th>
<th><b>Support:</b></th>
<th><b>Amount:</b></th>
<th><b>Paid:</b></th>
<th><b>Created:</b></th></tr>
<tr><td><img src="/images/' .$row["image"]. '" style="width:128px; height:128px;"/></td>
<td>'.$row["image_text"].'</td>
<th>'.$row["id"].'</td>
<td>'.$row["support"].'</td>
<td>'.$row["Amount"].'</td>
<td>'.$row["Paid"].'</td>
<td>'.$row["created"].'</td></tr>';
}
echo "</table>";

更新:
我没有注意到刘易斯纽森指出的那样,你实际上每次都使用<th>而不是<td>。我已经更新了我的答案,包括while循环和表格的关闭。

谢谢先生们的评论,我能够解决我的问题,如下所示。

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT id, image, image_text, support, Amount, Paid, created  FROM 
images";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<table id='customers'>"; // start a table tag in the HTML
echo "<tr><th><b>Logo:</b></th>
<th><b>Details: </b></th>
<th><b>id: </b></th>
<th><b>Support: </b></th>
<th><b>Amount: </b></th>
<th><b>Paid: </b></th>
<th><b>Created: </b></th></tr>";
while($row = $result->fetch_assoc()) {

echo "<tr><th><img src=/images/" . $row["image"]. " " . 
"style='width:128px; height:128px'/></th>
<th>" . $row["image_text"]. " " . "</th>
<th>" . $row["id"]. " " . "</th>
<th>" . $row["support"]. " " . "</th>
<th>" . $row["Amount"]. " " . "</th>
<th>" . $row["Paid"]. " " . "</th>
<th>" . $row["created"]."</th></tr><br>";
}
echo "</table>"; //Close the table in HTML  
// <tr><th>" . $row["image"]. " " . "</th>

} else {
echo "0 results";
}
$conn->close();
?>

最新更新