SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo url from database

    My PHP knowledge is not very good and I am already trying things for hours without any results. The problem is this. I have a echo with a hard coded url:

    Code:
    echo "<a class='fancybox' data-fancybox-group='gallery' href='http://diem.sothenwhat.com/museum_photos/photos/" . $row->photo . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";
    For certain reasons I need the href property: http://diem.sothenwhat.com/museum_photos/photos/ to come from the database! So in the database I created a new field called link.and placed the http://diem.sothenwhat.com/museum_photos/photos/ into that field and changed the echo into:

    Code:
    echo "<a class='fancybox' data-fancybox-group='gallery' href='$link" . $row->photo . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";
    but that isn't working. Can someone please help me out with this?

    Thank you in advance!!!!!!
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Where do you give $link it's value?
    If your retrieved database data is stored in $row, and assuming you updated your query to retrieve the link column as well, my guess is you'll need to echo $row->link

  3. #3
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works great Guido Thanks
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  4. #4
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to change the href based on a certain id. Thi is what I have right now:
    Code:
    while ($row = $stmt->fetchObject()) { 
      $imgString .= "<a class='fancybox' data-fancybox-group='gallery' href='$row->link" . $row->photo . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";  
    }
     echo $imgString;
    When the photo id is for example 10 the
    Code:
    href='$row->link" . $row->photo
    echo should not include $row->photo but just $row->

    How would I do that? Thank you in advance
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  5. #5
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this:
    Code:
    while ($row = $stmt->fetchObject()) { 
      $imgString .= "<a class='fancybox' data-fancybox-group='gallery' href='$row->link" . $row->photo . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";  
    }
    if ($photo_id == 74){
      $imgString += "<a class='fancybox' data-fancybox-group='gallery' href='$row->link" . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";
    } 
    echo $imgString;
    I dont get an error but it isn't working either.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  6. #6
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying for hours but without success. Is it possible to have a if else statement within the href tag e.a.

    $imgString .= <a if ($photo_id == 74) { href='http://www.youtube.com/watch?v=IC9wzNu-k3E'>} else { <a href='$row->link" . $row->photo . "'>}

    Or something similar?

    Thank you in advance
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    while ($row $stmt->fetchObject()) { 
        if (
    $photo_id == 74){
            
    $imgString += "<a class='fancybox' data-fancybox-group='gallery' href='$row->link"'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" $row->photo "' /></a>";
        } else { 
            
    $imgString .= "<a class='fancybox' data-fancybox-group='gallery' href='$row->link$row->photo "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" $row->photo "' /></a>";  
        }


  8. #8
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guido. I tried your suggestion but it isn't working. Have a look at the site. Click on the tab Porsche at the bottom. l The middle image you see is the one that should open a youtube movie instead of a larger image. But when you roll over the image you'll see still the row photo after the actual link. What should I do to avoid that?

    Thank you
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I saw it for a moment, but the next time i clicked on porsche, the .jpg part disappeared. So I guess you got it to work?

  10. #10
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guido no it isn't working. I made a mistake in the echo; Please have a look now. The photo extension is there again?
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Are you sure $photo_id contains the value of the photo id? Maybe it should be $row->photo_id ?

  12. #12
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guide. You're absolutely right. This is what I have now:

    Code:
        while ($row = $stmt->fetchObject()) {
            if ($row->photo_id == 74){
                $imgString .= "<a class='fancybox-media' href='$row->link" . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";
            } else {
                $imgString .= "<a class='fancybox' data-fancybox-group='gallery' href='$row->link" . $row->photo . "'><img src='http://diem.sothenwhat.com/museum_photos/carousel/" . $row->photo . "' /></a>";
            }
        }
    and it is working great. Thanks a lot!!!!!
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


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
  •