Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is wrong with this piece of code? html + php

i've a simple function, which has two parameters, one for the image url, and other for the attributes for the image

function image_found($url,$attributes)
{
    if(@getimagesize($url))
    {
        echo '<img src="'.$url.'" '.$attributes.'/>';
    }
    else
    {
        echo '<img src="'.base_url().'/site_images/image_not_found.svg" '.$attributes.'/>';
    }
}

now what i'm trying to do is create a clickable image, if the image is found, now this is the html code

echo '<div class="panel-body">';
echo '<div class="col-md-12 col-lg-12 col-sm-12 text-center">';
$url = base_url().'product_images/'.$result->product_image.'.'.$result->image_type;
$attributes = 'height="200px" width="100%"';
echo '<a href="product.com/full/url">'.image_found($url,$attributes).'</a>';
echo '</div>';
echo '</div>';

and this is the output i'm getting

<div class="panel-body">
    <div class="col-md-12 col-lg-12 col-sm-12 text-center">
        <img src="http://localhost/nsc/product_images/7908076366784972032090.jpg" height="200px" width="100%"/>
        <a href="#"></a>
    </div>
</div>

i don't know what is wrong here, i'm using bootstrap

like image 374
runningmark Avatar asked Nov 09 '22 15:11

runningmark


1 Answers

Just use return statements instead of echo in your function and your problem should be solved ;-)

like image 53
user3714751 Avatar answered Nov 14 '22 21:11

user3714751