Creating image grid using PHP

The name of the pictureThe name of the pictureThe name of the pictureClash 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++;

?>



the gap after 12th picture



I want the output to look like this
2



and the css i using is w3-quarter from w3.css





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






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.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard