I have problem in my task where I suppose to display my record in horizontally with 3 columns
Unfortunately, my display is become vertical.
The task require us to use modulus (%) operator in order to display the records. The records are stored in database (id, title, picture, category, author). There are 11 books that store in database. Here is my PHP code:
<?php
include_once('config.php');
$result = mysqli_query($mysqli, "SELECT * FROM books ORDER BY id ASC");
?>
<style>
img {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
width: 200px;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
}
.p3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
color: blue;
}
</style>
<div class="container">
<center>
<h1>Koleksi Buku Peribadi</h1>
<table>
<?php
$x=11;
$y=3;
$i=$x % $y;
while($i && $book = mysqli_fetch_array($result)) {
?>
<tr>
<td>
<img src="Gambar-buku/<?php echo $book['picture'];?>">
<p class='p2'>Penulis:<span class='p3'> <?php echo $book['author'];?> </span>
<br> <i><?php echo $book['category'];?></i>
</p>
<center><button type="button">Details</button> </center>
</td>
</tr>
<?php
$i++; }
?>
</table>
</center>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…