建立连接后我目前拥有的代码
$sql = "SELECT ID, NAME FROM players";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
// Outputting HTML and the data from the DB. Change to $row['the name of the field you want']
echo "<div class='caption'><h3><img src='http://placehold.it/180x180' alt=''>" . $row['NAME'] . "</h3><p>";
}
} else {
echo "No players to show";
}
$conn->close();
?>
它是CSS我应该专注于使我看起来像我想要的方式? 抱歉,我是一个新人,不能让我的头围绕它哈哈
答案 0 :(得分:-1)
试试这个: 我添加了一个名为i的计数器,它会在列出5个名称后更改div。然后我将div设置为50%宽度并向左浮动,允许2个div并排。
<style>
.caption
{
width:50%;
float:left;
}
<?php
$sql = "SELECT ID, NAME FROM players";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<div class='caption'>";
while($row = $result->fetch_assoc()) {
$i = 0;
if($i>=4)
{
$i = 0;
echo "</div><div class='caption'>";
// Outputting HTML and the data from the DB. Change to $row['the name of the field you want']
<h3><img src='http://placehold.it/180x180' alt=''><h3>" . $row['NAME'] . "<h3>";
}
} else {
echo "No players to show";
}
$conn->close();
?>
</div>
答案 1 :(得分:-1)