Jump to content

Recommended Posts

So, I currently have a script (in beta mode, only works when the sun shines), that can upload an image and store directly in a mysql database (using the BLOB data type); the script is also able to retrieve the BLOB data and display them vertically on the page; I actually need to dsiplay them horizontally across the page instead. So currently the retrieved images are printed in this format:

1

2

3

4

5

6

7

8

 

and I need it to print this way:

1 2 3 4

5 6 7 8

 

sounds like a for loop somewhere... any takers on how to implement the feature?

 

You could actually just use CSS styling to achieve this. Give the images display: inline-block; and they will tile horizontally until they get to the edge of the parent container, then drop down and continue on.

 

Example: http://jsfiddle.net/fzbe4jpm/

 

To achieve it with a for loop, you can use the modulus operator to decide when to insert a line break.

$i = 1;
foreach ($images as $image) {
	if ($i % 4 === 0) { 
		echo '<br />';
	}

	echo '<img src="' . $image . '" />';

	$i++;	
}
Something like that.

You could actually just use CSS styling to achieve this. Give the images display: inline-block; and they will tile horizontally until they get to the edge of the parent container, then drop down and continue on.

 

Example: http://jsfiddle.net/fzbe4jpm/

 

To achieve it with a for loop, you can use the modulus operator to decide when to insert a line break.

$i = 1;
foreach ($images as $image) {
	if ($i % 4 === 0) { 
		echo '<br />';
	}

	echo '<img src="' . $image . '" />';

	$i++;	
}
Something like that.

 

Thank you for the tip. A for loop did actually work... This prints the result/format that was required:

 

<html>

<body>

<table border="1"><tr>

<?php

for ($number = 1; $number <= 8; $number++) {

if ($number % 4 === 1){

echo '</tr>';

}

echo '<td>'.$number.'</td>';

}

?>  

</tr></table>

</body>

</html>

 

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.