我需要制作一张表格,每行最好有4到5张图片,但它会在我的页面上继续。任何帮助将不胜感激
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "imageupload";
$query = "SELECT id, url, name from images ";
$connect = mysqli_connect($host,$user,$password,$database) or die("Problem connecting.");
$result = mysqli_query($connect,$query) or die("Bad Query.");
mysqli_close($connect);
while($row = $result->fetch_array())
{
echo "<td>";
echo "<td><h2><img src=" . $row['url'] . " width=150 height=150/></h2></td>";
echo "<td><h2>" .$row['name'] . "</h2></td>";
echo "</td>";
}
?>
<table>
答案 0 :(得分:-1)
你可以试试这个:
echo "<table><tr>";
foreach($row = $result->fetch_array()) {
if($row['id'] % 4 == 0) { //Change it to 5 if you want 5 images per row
echo "</tr><tr>";
}
echo "<td><img src='" . $row['url'] . "' /></td>";
}
echo "</tr></table>";