Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:30:10+00:00 2026-06-17T08:30:10+00:00

I have a php script that queries a database for images, and then outputs

  • 0

I have a php script that queries a database for images, and then outputs the images onto the screen with a foreach loop. All the images have the same width, but different heights. I want to display these images in 2 columns. The foreach loop means that I can’t explicitly define two columns in the html and place the images into the column. As I have it now on the site, each image is floated left, but this creates awkward vertical spaces between images of different heights.

Not sure if I’m explaining this well, so here’s a jsfiddle that shows what I have now and what I want it to look like. In here I have coded each item so that it look right, but when it’s live I wont know each images height or be able to change it.

If there is a way to put two columns directly in the html, it needs to output the images like so, which is counterintuitive for a loop in columns:

1 2

3 4

not

1 3

2 4

Ideally I wont need to use some odd php or javascript workaround, but instead will be able to just edit the css for the image boxes

.img_box {
  float: left;
  width: $img-width;
  max-height: 600px;
  padding: 0px 0px 0px 20px;
  margin-top: 20px;
}
.rate_img {
  width:$img-width;
}

php after pulling image info from database

foreach ($result as $row) {
    echo '
     <div class="img_box">
        <a href="' . $row['file_loc'] . '"rel="lightbox[main]" title="' . $row['name'] . '" >
            <img src="' . $row['file_loc'] . '" class="rate_img" />
        </a>
     </div>';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:30:11+00:00Added an answer on June 17, 2026 at 8:30 am

    I think it’s impossible to get the effect that you want in just html and css.

    To fill up the available white-space you would need to use something like javascript, take a look for example at the jQuery Masonry plugin (there are probably jQuery-less options as well…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP search script that queries a MySQL database and then parses
I have a PHP script that runs database queries. Now, if a query fails,
I have a PHP script that runs very simple queries on a MySQL database
I have php script that creates a temporary watermark image for users that are
I have a php script that inserts data from an Android app into a
I have a php script that watches for the newest json file in a
I have a php script that grabs links from another website. I am storing
I have a PHP script that very much like a commenting system, but requires
I have a PHP script that opens an XML document, gets the DOM and
I have a PHP script that creates large complex tables. I am attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.