I know this has been answered but, i want to display photos in 4 columns, and how ever many rows (depending on how many pics).
I tried searching the forums, but i am not sure what to search for
Printable View
I know this has been answered but, i want to display photos in 4 columns, and how ever many rows (depending on how many pics).
I tried searching the forums, but i am not sure what to search for
if $count++ % 4 == 0 && $count != 0 Create another tr?
im sorry, you lost me. can you please repost with a description and maybe with PHP tags, thanks.
This is just created on the fly so there might be errors but it's more or less something like this
Code:$count = 0;
echo "<tr>";
foreach ($pics as $pic) {
echo "<td><img></td>";
if ($count++ % 4 == 0 && $count != 0) {
echo "</tr><tr>";
}
}
echo "</tr>";
Ops, it should be
Code:$pics = array('pic 1', 'pic 2', 'pic 3', 'pic 4', 'pic 5', 'pic 6');
echo "<table><tr>";
foreach ($pics as $pic) {
if ($count++ % 4 == 0 && $count != 0) {
echo "</tr><tr>";
}
echo "<td>$pic</td>";
}
echo "<tr></table>";
i am going to be getting the pictures from a database, does that make a difference?
Nope.
well would the array be something like this:
PHP Code:$pics = mysql_fetch_array
Are you storing it as blob? Or just reference path? If it's blob, it would be another thread I guess but if it's just reference path, it would be something like
But I'm fond of encapsulating the DAO to another layer that's why I have examples like above. Assuming I encapsulated the results to the $pics array.Code:$result = mysql_query("select img from img_table");
echo "<table><tr>";
$count = 0;
while ($row = mysql_fetch_array($result)) {
extract($row);
if ($count++ % 4 == 0 && $count != 0) {
echo "</tr><tr>";
}
echo "<td><img src='$img'/></td>";
}
echo "<tr></table>";
i think thats exactly what i am looking for. but i have to go right now. I will test it in the morning
thanks!
ok the code didnt work. Here is what i worked out:
and here is the source from the browser:PHP Code:<?php
$result = mysql_query("SELECT * FROM `pictures` WHERE album='$_GET[albumid]' AND member_id='$_SESSION[member_id]'");
echo "<table><tr>";
$count = 0;
while ($a = mysql_fetch_array($result)) {
extract($row);
if ($count++ % 4 == 0 && $count != 0) {
echo "</tr><tr>";
}
?>
<td>
<img src='includes/image_resize.php?<?=$a['url']?>' title='<?=$a['caption']?>'><br>
<?=$a['caption']?><br>
//some HTML here...
</td>
<?PHP
}
echo "</tr></table>";
?>
HTML Code:<!--############ START ############ -->
<table><tr><tr></table>
<!--############ END ############ -->
A little modification. $count = 0 to $count = 1 and works for me btw.
Edit: Page SourceCode:<?php
mysql_connect('localhost', 'test', 'password');
mysql_select_db('test');
$result = mysql_query("select path from pictures");
echo "<table><tr>";
$count = 1;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
extract($row);
echo "<td><img src='$path'></td>";
if ($count++ % 4 == 0) {
echo "</tr><tr>";
}
}
echo "</tr></table>";
?>
Code:<table><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr><tr><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td><td><img src='images/pic1.png'></td></tr></table>
i must be having a mysql error then. Thanks!
i have used this code like 2 or 3 times without any problems, and not i am trying to implement it on another site, and it is telling me i have an "unexpected $end on line 1".
I normally get thoes when i open a if statment, and dont close it.
I checked all the if / else statments and they all closed... and i am not sure what is happening
Check that no path is specified in the auto_prepend_file INI setting.
i cant access my ini file
ok, no file is there.