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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.