SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Scratching My Head Over This.

    I added some code to my photo gallery web page to provide for scrolling to the previous image or the next image in the category. I use an array of all the photo keys in the category to deal with the first and last image.

    When I have some debugging print_r and echo statements added everything works as I expect. When I remove the debugging statements it does not work. (?!) The code seems to act like I have only have a single photograph in the gallery. But I don't know what is going on when I don't have the debugging lines of code, because ... I don't have the debugging lines of code. There are no errors being recorded in the log.

    Here is the code I added:

    Code:
    $allphotosquery = "SELECT photo_id FROM gallery_photos WHERE photo_category=:cid ORDER by pair_order";
    
    try {
        $stmt = $dbh->prepare($allphotosquery);
        $stmt->bindValue(':cid', $cid, PDO::PARAM_INT);
        $stmt->execute();
        while( $rows = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
           $photos[] = $rows['photo_id'];
         }   
      } catch (PDOException $e) {
            echo 'Error getting photograph information: ' . $e->getMessage();
      }
    /*
      print_r($photos);
    */
      $prev_str = "<a href=\"viewgallery.php?cid=$cid&pid=%pid\">PREV</a>";
      $next_str = "<a href=\"viewgallery.php?cid=$cid&pid=%pid\">NEXT</a>";
      
      $key = array_search( $pid, $photos ); 
    /*  
      echo "Key is: " . $key;
    */  
      if ( $key === FALSE ) {
          echo "Key is false";
          $prev = "&nbsp;&nbsp;&nbsp;&nbsp;";
          $next = "&nbsp;&nbsp;&nbsp;&nbsp;";
      } else {
    /*     echo "Key is: " . $key;  */
            if ( $key == 0 ) $prev = "&nbsp;&nbsp;&nbsp;&nbsp;";
            else $prev = str_replace( '%pid', $photos[$key - 1], $prev_str );
            if ( $photos[$key] == end( $photos ) ) $next = "&nbsp;&nbsp;&nbsp;&nbsp;";
            else $next = str_replace( '%pid', $photos[$key + 1], $next_str );
      }
      
      $gap = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
      $contenttop .= "<br /><span class=\"prevnext\"><br />$prev$gap$next</span>";
    Executed like this I get the HTML:

    Code:
    <span class="prevnext"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="viewgallery.php?cid=3&pid=4">NEXT</a></span>
    But if I remove the comments around the print_r($photos) I get this for the print_r:

    Code:
     Array
    (
        [0] => 3
        [1] => 4
        [2] => 5
        [3] => 2
        [4] => 1
    )
    and this for the HTML:

    Code:
    <span class="prevnext"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="viewgallery.php?cid=3&pid=4">NEXT</a></span>
    I also get the correct HTML when I remove the comments around either of the echo $key statements.

    But I can't use the print_r and echo on my public site.

    I even tried touching the variables by added this code:

    Code:
      $key = array_search( $pid, $photos ); 
      $keycopy = $key;                                     <<<<< these lines
      $photoscopy = $photos;                             <<<<< these lines
    Any and suggestions appreciated.
    Stephen

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated.

    On closer look I see that I am getting the HTML for the href's. It is just not visible on the web page. Even stranger.
    Stephen

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Could you post a link so we can check it out?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured this out with fresh eyes this morning.

    It was my CSS.

    The href links were under my photograph. The print_r and echos moved things around.

    I changed the positioning and all is well.

    Thanks
    Stephen


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
  •