Results 1 to 17 of 17

Thread: [RESOLVED] Photo Album - Rows/Cols

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Resolved [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

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Photo Album - Rows/Cols

    if $count++ % 4 == 0 && $count != 0 Create another tr?

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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>";

  5. #5
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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>";

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  7. #7
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Photo Album - Rows/Cols

    Nope.

  8. #8

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Photo Album - Rows/Cols

    well would the array be something like this:

    PHP Code:
    $pics mysql_fetch_array 
    My usual boring signature: Something

  9. #9
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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.

  10. #10

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  11. #11

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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++ % == && $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

  12. #12
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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>

  13. #13

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Photo Album - Rows/Cols

    i must be having a mysql error then. Thanks!
    My usual boring signature: Something

  14. #14

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Photo Album - Rows/Cols

    Check that no path is specified in the auto_prepend_file INI setting.

  16. #16

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Photo Album - Rows/Cols

    i cant access my ini file
    My usual boring signature: Something

  17. #17

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Photo Album - Rows/Cols

    ok, no file is there.
    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
  •  



Click Here to Expand Forum to Full Width