|
-
Jul 22nd, 2007, 07:20 PM
#1
Thread Starter
WiggleWiggle
[RESOLVED] Photo Album - Rows/Cols
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
My usual boring signature: Something
-
Jul 22nd, 2007, 11:01 PM
#2
Fanatic Member
Re: Photo Album - Rows/Cols
if $count++ % 4 == 0 && $count != 0 Create another tr?
-
Jul 23rd, 2007, 02:32 AM
#3
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
im sorry, you lost me. can you please repost with a description and maybe with PHP tags, thanks.
My usual boring signature: Something
-
Jul 23rd, 2007, 02:37 AM
#4
Fanatic Member
Re: Photo Album - Rows/Cols
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>";
-
Jul 23rd, 2007, 02:39 AM
#5
Fanatic Member
Re: Photo Album - Rows/Cols
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>";
-
Jul 23rd, 2007, 02:41 AM
#6
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
i am going to be getting the pictures from a database, does that make a difference?
My usual boring signature: Something
-
Jul 23rd, 2007, 02:44 AM
#7
Fanatic Member
Re: Photo Album - Rows/Cols
-
Jul 23rd, 2007, 02:47 AM
#8
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
well would the array be something like this:
PHP Code:
$pics = mysql_fetch_array
My usual boring signature: Something
-
Jul 23rd, 2007, 02:56 AM
#9
Fanatic Member
Re: Photo Album - Rows/Cols
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
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>";
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.
-
Jul 23rd, 2007, 03:19 AM
#10
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
i think thats exactly what i am looking for. but i have to go right now. I will test it in the morning
thanks!
My usual boring signature: Something
-
Jul 23rd, 2007, 01:53 PM
#11
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
ok the code didnt work. Here is what i worked out:
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>";
?>
and here is the source from the browser:
HTML Code:
<!--############ START ############ -->
<table><tr><tr></table>
<!--############ END ############ -->
Last edited by dclamp; Jul 23rd, 2007 at 01:56 PM.
Reason: uncluttered php code
My usual boring signature: Something
-
Jul 23rd, 2007, 07:06 PM
#12
Fanatic Member
Re: Photo Album - Rows/Cols
A little modification. $count = 0 to $count = 1 and works for me btw.
Code:
<?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>";
?>
Edit: Page Source
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>
-
Jul 23rd, 2007, 07:45 PM
#13
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
i must be having a mysql error then. Thanks!
My usual boring signature: Something
-
Sep 15th, 2007, 03:03 PM
#14
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
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
My usual boring signature: Something
-
Sep 15th, 2007, 03:10 PM
#15
Re: Photo Album - Rows/Cols
Check that no path is specified in the auto_prepend_file INI setting.
-
Sep 15th, 2007, 03:35 PM
#16
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
i cant access my ini file
My usual boring signature: Something
-
Sep 15th, 2007, 03:41 PM
#17
Thread Starter
WiggleWiggle
Re: Photo Album - Rows/Cols
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|