Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

images from database mysql column not loading into img src.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

images from database mysql column not loading into img src.

Postby inoob » Wed Nov 07, 2012 7:23 am

Can someone tell me whats wrong with this?

Before reading, just know that I created the queries for fldImg and fldImageName. I just want to know why my images from the database arent being displayed with the code bellow, as everything else the pagination script works.


====================
show_image(stripslashes($row['fldImg']),stripslashes($row['fldImageName']));

}
echo ' '.$number_of_records;
function show_image($image_name, $alt)
{
if (file_exists("website.ca/images/'$image_name'"))
{
$dim_img = getimagesize('website.ca/images/'.$image_name);
echo '<img src="website.ca/images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"';
echo 'width = '. $dim_img[0] .' height = ' .$dim_img[1] . ' />';
}
else
echo 'Add your image here!';
}
====================

Basically I'm getting the image names from a column in the database and in each column it has 'image.jpg' and connecting it with the img src script from HTML so I can display the images from the mysql database. It has something to do with '$image_name' Im assuming.

No Images are displaying and I can't find the error. Doesn't seem like theirs anything wrong or I am just blind.

Thanks in advance!
Last edited by inoob on Wed Nov 07, 2012 7:46 pm, edited 1 time in total.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: images from database mysql column not loading into img s

Postby seandisanti » Wed Nov 07, 2012 2:38 pm

do a view source on the generated page and look at what it's putting for your image sources.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: images from database mysql column not loading into img s

Postby inoob » Wed Nov 07, 2012 7:45 pm

When I run the page, it doesn't even pop up the <img src=> anywhere in that particular area. All it shows is the echo of 'Add your image here!'.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: images from database mysql column not loading into img s

Postby simplypixie » Thu Nov 08, 2012 2:03 am

So based on your code, that is telling you that the file doesn't exist (i.e. PHP can't find the image file using the path and/or image name you have provided).

Not sure what website.ca is meant to be referencing in your file path, if your images folder is in your website root, then why not change the path to be
Code: Select all
/images/'.$image_name.'
and see if that works.

Also just echo out the $image_name on your page (within your function, before your if(file_exists) statement and make sure that you are getting the correct information.
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: images from database mysql column not loading into img s

Postby inoob » Thu Nov 08, 2012 9:20 am

Still no result. I tried /images/'.$image_name.' and it didn't work. Also echoed $image_name. No result.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: images from database mysql column not loading into img s

Postby simplypixie » Thu Nov 08, 2012 9:58 am

Which means nothing is populating the $image_name variable and that is your problem. Actually, I can see why now - your arguments when calling the show_image function don't match with the arguments in the function.

When calling show_image, your first argument should be the image name and the second should be the alt text as defined in
Code: Select all
function show_image($image_name, $alt)
whereas you are sending through the image id to $img_name and the image name to $alt
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: images from database mysql column not loading into img s

Postby inoob » Sat Nov 10, 2012 6:43 am

It works now. Your right.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.