Showing image depending on database value in php - php

I am trying to show image. I have an image named 5.png. And my database value $bnr_value also returns 5 correctly. but image does not show. How can I fix it?
<img src="new_img/header/career/"<?php echo $bnr_value.'png'; ?> alt="" class="image" style="max-width: 100%; ">

Try this:
<img src="new_img/header/career/<?php echo $bnr_value.'.png'; ?>" alt="" class="image" style="max-width: 100%; ">

//try this ..
<img src="new_img/header/career/<?php echo $bnr_value.'.png'; ?>" alt="" class="image" style="max-width: 100%; ">
=> "new_img/header/career/" is a not a full path ..
Example :- "new_img/header/career/<?php echo $bnr_value.'.png'; ?>" // set like this .

Related

i'm taking image url from database. But it is not working in img tag in php

The name of the column is : link. variable-type:varchar.
<img src="<?php echo$link;?>" style="width:300px; height:400px;" />
</html>
Your echo command could be missing an ";"
$link=$row['link'];
<img src="<?php echo $link; ?>" style="width:300px; height:400px;" />
Should work better.

Can't load image

As you can see, there is no image. What's wrong with this?
$displayProdCat .= '<div class="product">
<img src="Customer/images/product'.$ItemNo.'.jpg" width="170" height="150" />
<h3>'.$ItemName.'</h3>
<p class="product_price">Php '.$Price.'</p>
Add to Cart</div>';
Probably a wrong image url is specified. Look at the source.

As <img src="path"> src attribute don't take the path from another driver, so converted to base_64,not showing pirobox

As <img src="path"> src attribute don't take the path from another driver,
so in php, image get converted to base_64 then image codes are given as path in image tag, it's working well but not in internet explorer? i am posting code here
$img = "D://images/1s.jpg";
$image = file_get_contents($img);
$image_codes = base64_encode($image);
$img1="D://images/1.jpg";
$image1 = file_get_contents($img1);
$image_codes1 = base64_encode($image1);
?>
<div style="float:left; width:900px; display:block;">
<h2>Back to pirobox homepage demo1</h2>
<div class="demo"><a href="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" class="pirobox_gall" title="Spain 2009" >
<img src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" width="100" height="100" /></a></div>
</div>
<div style="float:left; width:90%; display:block; margin:5px 0 0 5px;">
</div>
</body>

Using a $_GET variable as img src

I am trying to link an image using the same name as a $_GET variable, example bellow:
The $_GET
$venue = $_GET['venue'];
Is it possible to use '$venue' as the image src example being something like
<div id="imgbox">
<img src="$venue.jpg" alt="venueimage" height="150" width="250">
</div>
My attempts so far have been unsuccessful, is it possible in a similar way to this or is there an alterantive?
Thankyou
You forgot your PHP tags and echo statement:
<div id="imgbox">
<img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
or shorthand:
<div id="imgbox">
<img src="<?= $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
As pointed out by Quentin we should take this a step further and sanitize our output:
<div id="imgbox">
<img src="<?= htmlspecialchars($venue); ?>.jpg" alt="venueimage" height="150" width="250">
</div>
You should be able to use <img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
I forgot to sanitize the code as well. You would need to add:
<img src="<?php echo htmlspecialchars($venue); ?>.jpg" alt="venuimage" height="150" width="250">

how to change image URL for each image of 4 products on each row?

I have a dynamic product table with 4 product on each row. I'm using CSS and not an html table.
I'm looking for a way to change all 4 images on each row to different urls and to do the same on all the other rows.
The reason for this is to use 4 sub domains as CDN to allow faster downloads.
Is this possible? i'm still very junior so need some assistance.
Below is my code and the image section is <img class="lazy" src="/images/loading.gif" data-original="<?=resize($i['image'],$settings)?>" width="170" height="250" alt="" />
You will notice that i'm using data-original as i'm using lazyload, the $settings is used for creating a cached version of the image.
Here's my code...
if($viewing=='retailer'){
if($i['category']!=$categoryCheck){?>
<div id="sub-sub"><?=$i['category_name']?></div>
<?
$categoryCheck = $i['category']; $y=1;
}?><? } ?>
<div class="package"<?=$y==4?' style="margin-right:0;"':''?><?=$y==1?' style="clear:left;"':''?>>
<div class="package-img"><a rel="nofollow" target="_blank" href="<?=$buyLink?>">
<?php $settings = array('w'=>170,'h'=>250,'canvas-color'=>'#ffffff'); ?>
<img class="lazy" src="/images/loading.gif" data-original="<?=resize($i['image'],$settings)?>" width="170" height="250" alt="" />
<noscript><img src="<?=resize($i['image'],$settings)?>" width="640" heigh="480"></noscript>
<? /* <img src="<?=$i['image']?>" width="640" heigh="480"> */ ?>
</a></div>
<div class="name"><a rel="nofollow" target="_blank" href="<?=$buyLink?>"><?=$i['item_name']?></a></div>
<div class="price"><p>£<?=$i['price']?></div>
<div class="mrtl rtl<?=$i['retailer']?>"></div>
<div class="retailer-image"><img src="/images/retailers/<?=$i['retailer_logo']?>" width="140" heigh="46" /></div>
</div>
<?
$y = $y==4 ? 1 : $y+1;
}
You need to change your function which returns the path to the image.
<?php
function resize(..., ...) {
static $i = 0;
$i++;
if ($i == 5) {
$i = 1;
}
return "http://cdn{$i}.domain/images/blah.gif";
}
?>

Categories