Jump to content

Displaying images horizontally with php


bitejones

Recommended Posts

Hi, sincerely hope i can get some help here. im pulling some images from my database but i want to display them horizontally for example 3 or 4 images in a row then it moves to a new row. so far i have only being able to display the images vertically. I am not sure if i should be using css or there is a way to do it with php. would appreciate any assistance. I have been tryin to get this done for sometime now and i need to complete this project. I'm new at this

Link to comment
https://forums.phpfreaks.com/topic/247799-displaying-images-horizontally-with-php/
Share on other sites

Im not sure how you coded or which variables you've been using but here is an example of a code I made for a photo gallery that displays images in a simple div from left to right.

 

<?php foreach($photos as $photo): ?>
    <div style="float: left; margin-left: 20px;">
        <a href="view.php?id=<?php echo $photo->id; ?>">
            <img src="<?php echo $photo->image_path(); ?>" width="200" />
        </a>
        <p><?php echo $photo->caption; ?></p>
    </div>
<?php endforeach; ?>

 

Just change the variables where there are echos to whichever variables you're using. I'm using OOP so my variables appear as $photo->id so perhaps yours would be a simple $id instead.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.