Creating image grid using PHP
Clash Royale CLAN TAG#URR8PPP
Creating image grid using PHP
I have a problem about PHP coding. I manage to display the first 12 image nicely on the image grid but after that, the picture seems to be out of place.
<?php
$i = 0;
while ($row = mysqli_fetch_array($result))
if ($i % 3 == 0)
echo "<div class='w3-quarter'>";
echo "<img src='images/$row['image']' onclick=onClick(this) style='width:100%'>";
if ($i % 3 == 2)
echo"</div>";
$i++;
?>
I want the output to look like this
2
and the css i using is w3-quarter from w3.css
Take a look at this: masonry.desandro.com
– Sarcoma
Aug 9 at 20:34
To handle this kind of issue with PHP, you have to know the image size ahead of time. Then you can do the math to determine how many will fit per row and column. Otherwise, you use JavaScript and CSS
– Ibu
Aug 9 at 20:38
@Sarcoma if i use masonry can i use PHP code as above? Because i need to retrieve all the image from my database
– Jun Sheng Lee
Aug 9 at 20:56
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You have to show us what you want the output to look like. Are you using any CSS grid frameworks?
– waterloomatt
Aug 9 at 19:21