Results 1 to 10 of 10

Thread: Echo three pictures in a row

  1. #1
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Echo three pictures in a row

    My name is justin and I'm very new to php.. I understand the basic(very Basics) and I'm trying to create a photo gallery with three pictures on each row. The picture names are in a table called (job_banner_t) and the image file name is in a row called fn..... I posted this in the past and got some pointers but, I just can't seem to get it right... My code that isn't working is listed below, and I would greatly appreciate any help...


    Code:
    <?
    
    
    
    
    
    include_once "accesscontrol.php";
    
    
    $sb = "select * from job_banners_t";
    $rsb = mysql_query($sb) or die(mysql_error());
    if(mysql_num_rows($rsb) > '0')
    
    {
    
    echo "<table align=center width=600><caption align=center><b>Photo Album </b></caption><tr><br><td colspan=2><hr width=100% height=1px color=#000099></td></tr>";
    
    
    
    
    while ($ab = mysql_fetch_assoc($rsb)) {
    $myimgs[] = $row['fn'];
    {
    echo '<table><tr>';
    for($x=0;$x<count($myimgs);$x++) {
    if ($x%3==0) { echo '</tr>'; }
    echo '<td><img src=\"http://$_SERVER[HTTP_HOST]$dir/photo_album/$ab[fn]\" width=\"120\" height=\"100\" /></td>';
    }
    echo '</tr></table>';
    
    
    ?>
    Last edited by djr33; 09-07-2010 at 02:16 AM. Reason: fixed [/code] tag

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Try changing this:
    if ($x%3==0) { echo '</tr>'; }
    to:
    if ($x%3==0) { echo '</tr><tr>'; }
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    captainjustin (09-07-2010)

  4. #3
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Still no Luck

    I'm not sure whats going on... Changing the if ($x%3==0) { echo '</tr><tr>'; } didn't do anything. It seems to be a syntax error or something. The page is blank and white when I try to see the page.

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It looks like you have several extra { brackets open, but missing } brackets to close those code blocks. Try adding a few (1-3) to figure out which one is the problem.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    captainjustin (09-07-2010)

  7. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Unless they're later in the script, in a part you didn't include here, your brackets aren't all in pairs. That could be a problem.
    PHP Code:
    <?  // you should use full tags:  <?php
    include_once "accesscontrol.php";

    $sb "select * from job_banners_t";
    $rsb mysql_query($sb) or die(mysql_error());
    if(
    mysql_num_rows($rsb) > '0')

    {  
    // <--   this one has no closing bracket

    echo "<table align=center width=600><caption align=center><b>Photo Album </b></caption><tr><br><td colspan=2><hr width=100% height=1px color=#000099></td></tr>";

    while (
    $ab mysql_fetch_assoc($rsb)) {
    $myimgs[] = $row['fn'];

    {  
    // <--   this one has no closing bracket

    echo '<table><tr>';
    for(
    $x=0;$x<count($myimgs);$x++) {
    if (
    $x%3==0) { echo '</tr>'; }
    echo 
    '<td><img src=\"http://$_SERVER[HTTP_HOST]$dir/photo_album/$ab[fn]\" width=\"120\" height=\"100\" /></td>';
    }
    echo 
    '</tr></table>';

    ?>
    Something else: All the code here is dependent on getting a result from your database query ( if(mysql_num_rows($rsb) > '0') ). Do you know that there is a result? Add this right after the $rsb = mysql_query($sb) or die(mysql_error()); line:
    PHP Code:
    if(mysql_num_rows($rsb) == 0){ echo 'no results to show'; } 

  8. The Following User Says Thank You to traq For This Useful Post:

    captainjustin (09-07-2010)

  9. #6
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Ok how about this?

    Ok so I got another script to work but it has one small problem.. When it echos the <image tag and the $[row] it adds some weird symbols and % stuff to the image name... Which in return does not display the image properly. The image location should be:

    http://oilfield-mariners.com/rabbit_...o_album/(Image Name)

    However when I right click on the blank image and copy the image location... This is what I get.

    http://oilfield-mariners.com/rabbit_...chor.jpg%5C%22


    Here is the
    Code:
    <?php
    include 'accesscontrol.php';
    // Set how wide you want your table
    $tblWidth = 4;
    // Make your query
    $sql = mysql_query("SELECT * FROM job_banners_t");
    $i = 1;
    echo '<table align=center>';
    // Check to see if any results were returned
    if(mysql_num_rows($sql) > 0){
    	echo '<tr>';
    	// Loop through the results
    	while($row = mysql_fetch_array($sql)){
    		echo '<td><img src=\"photo_album/'. $row['fn'] .'\" width=\"120\" height=\"100\" /></td>';
    		if($i == $tblWidth){
    			echo '</tr><tr>';
    			$i = 0;
    		}
    		$i++;
    	}
    	echo '</tr>';
    }else{
    	echo '<tr><td>No Results Found</td></tr>';
    }
    echo '</table>';
    ?>
    Any Suggestions?
    Last edited by djr33; 09-07-2010 at 02:44 PM. Reason: Use [/code] to finish [code] blocks.

  10. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Remove the \'s those are to escape the double quotes but you're not using them

    so this

    PHP Code:
    echo '<img src=\"photo_album/'$row['fn'] .'\" width=\"120\" height=\"100\" /></td>'
    should be

    PHP Code:
    echo '<img src="photo_album/"'$row['fn'] .' width="120" height="100" /></td>'
    Corrections to my coding/thoughts welcome.

  11. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    you can also get that kind of stuff if you have spaces in the filename.

  12. #9
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Thumbs up

    This example will help.

    Code:
    <?php
    mysql_connect('localhost','root','');
    mysql_select_db('exp_eng');
    
    $rsb = mysql_query("select name from about");
    
    while($ab = mysql_fetch_assoc($rsb)){
    $myname[] = $ab['name'];
    }
    
    echo '<table><tr>';
    
        for($x=0;$x<count($myname);$x++){
              if($x%3==0){
                 echo '</tr><tr>';
               }
    
             echo '<td>'.$myname[$x].'</td>';
    
                
        }
    echo '</tr></table>';
    ?>

  13. The Following User Says Thank You to katierosy For This Useful Post:

    captainjustin (09-26-2010)

  14. #10
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Ok so I got this script that works fine but I was wondering if there is a way for the thumb nails to load faster... I'm using the fancy box light box picture viewer.. Got any suggestions?

    Code:
    <?
    $submit=fn;
    $order_type=fn;
    if (!$ByPage) $ByPage=8;
    if (!$Start) $Start=0;
    // Set how wide you want your table
    $tblWidth = 4;
    // Make your query
    $sql = mysql_query("SELECT * FROM photo_album order by date desc limit $Start,$ByPage ");
    $i = 1;
    echo '<table align=center>';
    // Check to see if any results were returned
    if(mysql_num_rows($sql) > 0){
    	echo '<tr>';
    	// Loop through the results
    	while($row = mysql_fetch_array($sql)){
    		echo '<td><a rel="example_group" href="images/'. $row['fn'] .'" title="'. $row['title'] .'"><img src="images/'. $row['fn'] .'" width="120" height="100"  />    </a><br><center><a href="delete_pic.php?fn='. $row['fn'] .'" ><img src="icons/delete.gif" width="21" height="16" title="Delete Picture" border="0"/></a>&nbsp;<a href="edit_comments.php?fn='. $row['fn'] .'" ><img src="icons/comments.png" width="16" height="16" title="Edit Comments" border="0"/></a></td>';
    		if($i == $tblWidth){
    			echo '</tr><tr>';
    			$i = 0;
    		}
    		$i++;
    	}
    	echo '</tr>';
    }else{
    	echo '<tr><td>No Pictures Posted Yet!</td></tr>';
    }
    echo '</table>';
    $cp = "select count(fn) from photo_album";
    $rcp = mysql_query($cp) or die (mysql_error());
    $ap = mysql_fetch_array($rcp);
    $a = $ap[0];
    
    echo "<table width=500 align=center cellspacing=0><tr>";
    
    if ($a <= $ByPage && $Start == '0')
    {
    
    }
    
    elseif ($a > $Start + $ByPage && $Start + $ByPage >= $a || $Start == 0 )
    {
    	$nom = $Start + $ByPage;
    	echo "<td align=right><a class=TNA href=\"admin_album.php?submit=$submit&order_type=$order_type&Start=$nom\">Next Page <img src=\"icons/next.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/></a></td>";
    }
    elseif ( ($Start < $a && $Start > $ByPage) || ($Start + $ByPage >= $a))
    {
    	$nom1 = $Start - $ByPage;
    	echo "<td align=left><a class=TNA href=\"admin_album.php?submit=$submit&order_type=$order_type&Start=$nom1\"><img src=\"icons/back.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/> Back</a></td>";
    }
    
    
    echo "</tr></table>";
    
    exit;
    
    
    
    ?>
    Last edited by jscheuer1; 11-30-2010 at 10:57 AM. Reason: format code

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •