How to do a Horizontal foreach in PHP

I'm trying to have my images appear horizontally but they come up vertically. How can I do this? I've tried floating left with CSS but nothing. This is my code:

<?php 

$db = new SecureSqlHelper_Database;

$county = 'New York';
$active = '1';
$feature = '1';

$result=$db->singleQuery("SELECT * FROM units WHERE active=?int and feature=?int and county=?sql ORDER BY RAND() LIMIT 5", Array($active,$feature,$county));

foreach($result as $row){
	
		$img01 = explode(',', trim($row['images']));
			
			$image01 = $img01[0];
	
				
			 if (!empty($image01))
			
			 { echo "<a href='https://".strtolower (preg_replace('/\s+/', '',$row['county'])).".mydomain.com/listing.php?id=".$row['id']."' style='color: #000'><img src='https://mydomain.com/user/images/classified/tn/".$image01."' width='50%'></a>" ;
			  } 
			  
			 else {  echo "<a href='https://".strtolower (preg_replace('/\s+/', '',$row['county'])).".mydomain.com/listing.php?id=".$row['id']."' style='color: #000'><img src='https://mydomain.com/user/images/no-image.png' width='75%'></a>";  
			   
			  };
		
			}

?>

Open in new window

Genesis5150Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
It would be helpful to see the page,you are using mixed widths whose sum is more than 100%
Marco GasiFreelancerCommented:
The layout of your page and its elements depends exclusively by CSS rules, not by the php code. So, foreach synatx has nothing to do with your problem.
The best thing you can do to get better help is to provide us a link to the live page so we can see it and play with css rules using Firebug or Developer Tools. If a link to the page is not an option, please let us know if you're using a framework like bootstrap and post here your cutom css.
Marco GasiFreelancerCommented:
If you're not using a framework, I stronlgy encourage you to do it. Bootstrap is a good choice: it provides a solid evironment where you can deply your custom styles and it avoids you have everytime to reinvent the wheel :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Some advice
1. When posting code it makes a big difference if you format the code in a way that makes it easy to read. Consider the reworked code below - it is functionally identical to the code you posted but easier to read
<?php 
$db = new SecureSqlHelper_Database;

$county = 'New York';
$active = '1';
$feature = '1';

// By using HEREDOC we can layout the query over multiple lines
$query = <<< QUERY
SELECT * FROM units
  WHERE active=?int AND feature=?int AND county=?sql 
  ORDER BY RAND() 
  LIMIT 5
QUERY;

$result=$db->singleQuery($query, Array($active,$feature,$county));

foreach($result as $row) {
  $img01 = explode(',', trim($row['images']));
  $image01 = $img01[0];
  
  // Create the URL to the Listing page - it is common 
  // to both so create outside of if. Split over multiple lines
  // breaking on concatenation (.) so it is easy to see what 
  // the various bits are

  $url = strtolower (preg_replace('/\s+/', '',$row['county'])) 
    . '.mydomain.com/listing.php?id=' 
    . $row['id'];
  
  if (!empty($image01)) { 
    // Use HEREDOC to output string which allows for use of 
    // single and double quotes. Enclose variables in { } to 
    // remove ambiguity
    
    echo <<< HTML
      <a href="https://{$url}" style="color: #000">
        <img src="https://mydomain.com/user/images/classified/tn/{$image01}" width="50%">
      </a>;
HTML;
  } 
  else {
    echo <<< HTML
    <a href="https://{$url} style="color: #000">
      <img src='https://mydomain.com/user/images/no-image.png' width='75%'>
    </a>
HTML;
  }
}
?>

Open in new window


2. Post code that is relevant to the question. The above codes output is one or more links to image files without a context as to the container they are being created on AND / OR the CSS that is applied to the parent containers and links / images - it is not possible to give you a comprehensive answer. Posting a link would be ideal - failing that the rendered html and the corresponding styles.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.