Reputation: 9778
I am getting the image path from database in this foreach
foreach($image as $row){
$value = $row['dPath'];
$imgpath =base_url()."images/".$value;//this is not taken
$imgpath = base_url()."images/con_icon.jpg";//this$imgpath is taken
echo $value;
when i give $imgpath as $imgpath = base_url()."images/con_icon.jpg"; it is accepted in
<img src="<?php echo $imgpath; ?>" and image is displayed
But when i give $imgpath as $imgpath =base_url()."images/".$value;
but echo $value;
results con_icon.jpg
The image is not displayed
what is the problem
EDIT:
echo $imgpath =base_url()."images"."/".$value;
echo $img = base_url()."images/con_icon.jpg";
gave me this
http://localhost/ssit/images/con_icon.jpg
http://localhost/ssit/images/con_icon.jpg
then why cant i get this in my <img>
<img src="<?php echo $imgpath; ?>" name=b1 width=90 height=80
border=0 onmouseover=mouseOver() onmouseout=mouseOut()>
Upvotes: 0
Views: 756
Reputation: 265221
make sure your $value
does not contain extra whitespace at the front or end. use
$value = trim($value);
to remove whitespace. also echo
is not the best way to quick-debug variables, use var_dump
instead.
and please make sure to escape your imagepath to prevent XSS
edit
you cannot say <img src="<?php echo $imgpath; ?>" name=b1 width=90 height=80
border=0 onmouseover=mouseOver() onmouseout=mouseOut()>
because you have whitespace at the end of your string. use <img src="<?php echo trim($imgpath); ?> … />
if you have to use it this way.
apart from that, quote your attributes: onmouseover="mouseOver"
, don't use parentheses after your event handler names (unless mouseOver()
returns a function—i don't think you are doing that …). and you should use urlencode
for your imagepath, to lock out all those malicious hackers who want to harm your users
Upvotes: 3
Reputation: 382696
Make sure that $value
is not coming empty:
var_dump($value);
Also, you may try this instead:
$imgpath = get_bloginfo('template_url') . "/images/" . $value;
Upvotes: 0