Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts

    Breaks in dynamic HTML causing problems

    I actually had a thread posted in the javascript frameworks forum, but after a lot more testing I think this is a PHP issue.

    I'm using PHP to dynamically create a photo gallery. It calls the file name and description from the DB then creates the containing div.

    I'm also using the jQuery plugin 'fancybox', which I originally thought was causing the problem.

    I eventually realised the problem was breaks in my anchors. Though the thumbs show fine, the images won't open in fancybox!
    Below is taken from my source, the top entry being one I 'fixed' manually, the bottom being one of the dynamic enteries:

    Code:
    <div class="thumb">
       <a href="http://www.jerseymet.gov.je/images/foglifting.jpg" rel="gallery_image" title="Fog lifting at Jersey Airport">
    
    	<img src="http://www.jerseymet.gov.je/images/foglifting.jpg" alt="Fog lifting at Jersey Airport" />
                                        
                     <p title="Fog lifting at Jersey Airport">Fog lifting at Jersey Airport</p>
                                    
    								</a></div>
                        <div class="thumb">      <a href="http://www.jerseymet.gov.je/images/foglifting.jpg
    " rel="gallery_image" title="Fog lifting at Jersey Airport
    "><img src="http://www.jerseymet.gov.je/images/foglifting.jpg
    " alt="Fog lifting at Jersey Airport
    " />            <p title="Fog lifting at Jersey Airport
    ">Fog lifting at Jersey Airport
    </p>    </a>   </div>
    And below is my PHP code including the manual one.
    PHP Code:
    <div class="thumb">
       <a href="http://www.jerseymet.gov.je/images/foglifting.jpg" rel="gallery_image" title="Fog lifting at Jersey Airport">
        <img src="http://www.jerseymet.gov.je/images/foglifting.jpg" alt="Fog lifting at Jersey Airport" />
                                        
                     <p title="Fog lifting at Jersey Airport">Fog lifting at Jersey Airport</p>
                                    
                                    </a></div>
                        <?php
                        
                        $result 
    get_row("gallery""*");
                        
                        while (
    $row mysql_fetch_assoc($result)) {
                            
                            
    $image $ImagePath.$row['path'];
                            
    $des =  $row['description'];
                            
                            echo 
    '<div class="thumb">
                                
                                    <a href="'
    .$image.'" rel="gallery_image" title="'.$des.'">
                                   <img src="'
    .$image.'" alt="'.$des.'" />         
                                    <p title="'
    .$des.'">'.$des.'</p>
                                    </a>
                                    
                                  </div>'
    ;                        
                        }
                        
    ?>
    I don't see where I've gone wrong. I've never had any issues like this before.
    Is the breaking up of tags like that normal of PHP? Seems strange.

    Thanks.
    Last edited by dan-dan; 04-14-2012 at 03:12 PM.

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    OK, I got it working, but I don't like the solution.

    The entire issue was the the closing quotation of the anchor breaking onto the next line.
    So I removed them, and although it now works on all browsers, it's not correct HTML.

    I also tried adding the quotations here:
    PHP Code:
    $image '"'.$ImagePath.$row['path'].'"'
    That didn't do anything either (as expected).

    Anyone have any ideas on how to fix this properly, retaining the proper HTML.

    PHP Code:
    <a href='.$image.' rel="gallery_image" title="'.$des.'"

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    $image = trim($image)

    Or you could find out where there are linebreaks in your image names

  • Users who have thanked NancyJ for this post:

    dan-dan (04-14-2012)

  • #4
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    That's the thing, there are no breaks within the filenames whatsoever, Ive already checked that.

    However, trim did fix it properly.

    Thank you.


  •  

    Posting Permissions

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