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:


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: [B]http://diem.sothenwhat.com/museum_photos/photos/[/B] to come from the database! So in the database I created a new field called link.and placed the [B]http://diem.sothenwhat.com/museum_photos/photos/[/B] into that field and changed the echo into:


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!!!

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

Works great Guido :slight_smile: Thanks

I need to change the href based on a certain id. Thi is what I have right now:


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

href='$row->link" . $row->photo

echo should not include $row->photo but just $row->

How would I do that? Thank you in advance

I tried this:


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.

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


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

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

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?

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?

Are you sure $photo_id contains the value of the photo id? Maybe it should be $row->photo_id ?

Hi Guide. You’re absolutely right. This is what I have now:


    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!!! :slight_smile: