User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,027 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3322 | Replies: 11
Reply
Join Date: Oct 2007
Posts: 19
Reputation: tryphy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tryphy's Avatar
tryphy tryphy is offline Offline
Newbie Poster

How to retrieve images from database

  #1  
Oct 15th, 2007
<?php
$conn = mysql_connect("localhost", "root", "general");
mysql_select_db("cms");
$result = mysql_query("SELECT * FROM Category");
echo "<table width='400' border='1' cellpadding ='3' cellspacing ='4' bordercolor='#45310F' fontcolor=#FFFFFF>";

//$cimage =
while($take = mysql_fetch_array($result))
{
echo"<tr><tr>";
echo "<tr><td>";
print $take['cat_name']."<br>";
echo "</td><td>";
print $take['cat_desc']."<br>";
echo "</td></td>";
echo "<t6><td>";
echo $take['cat_image']."<br>";
echo "</td></tr></tr>";
echo "<tr><tr>";
}
echo "</font>";
echo "</table>";
echo "<br><br><br>";
mysql_close($conn);
?>

this is my code to get the images from the database...
i have uploaded the images...
but..when i tried to view it only the image name appears..the image doesnt appear...
The image name in the mysql is called cat_image
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 189
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: How to retrieve images from database

  #2  
Oct 15th, 2007
My suggestion is to put the path to the image in the database. eg http://www.[name].com/images/cat_image.jpg
and then echo it inside an image tag.
Last edited by Venom Rush : Oct 15th, 2007 at 12:36 pm.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: How to retrieve images from database

  #3  
Oct 15th, 2007
echo <img src=$take['cat_image']>.
put it inside the image...
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 19
Reputation: tryphy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tryphy's Avatar
tryphy tryphy is offline Offline
Newbie Poster

Re: How to retrieve images from database

  #4  
Oct 16th, 2007
thanks...
will try and let know how it wrks..
Reply With Quote  
Join Date: Oct 2007
Posts: 19
Reputation: tryphy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tryphy's Avatar
tryphy tryphy is offline Offline
Newbie Poster

Re: How to retrieve images from database

  #5  
Oct 16th, 2007
i tried through it ..but i get an error...
Parse error: syntax error, unexpected '<' in ....
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: How to retrieve images from database

  #6  
Oct 16th, 2007
echo "<img src='.$take['cat_image'].'>";

put necessary quotes to display image.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: How to retrieve images from database

  #7  
Oct 16th, 2007
oops!I also made the wrong concatenation. try this one if the latter produces the same error.

echo "<img src=' ".$take['cat_image']." '>";
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 189
Reputation: Venom Rush is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Junior Poster

Re: How to retrieve images from database

  #8  
Oct 16th, 2007
The way I was thinking was to upload the image to the ftp and then INSERT the path to where the image is inside the database.

Then essentially you'd retrieve the path of the image from the database and insert it inside an img tag.
Reply With Quote  
Join Date: Oct 2007
Posts: 19
Reputation: tryphy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tryphy's Avatar
tryphy tryphy is offline Offline
Newbie Poster

Re: How to retrieve images from database

  #9  
Oct 16th, 2007
Originally Posted by Venom Rush View Post
The way I was thinking was to upload the image to the ftp and then INSERT the path to where the image is inside the database.

Then essentially you'd retrieve the path of the image from the database and insert it inside an img tag.



Hi....
venom rush....
Thanks for the suggestion...i will try that also...

But the echo one works...
i can see only the image tag...that is the box, but not the image....
when i upload the image...i upload into a folder ..
and also to mysql..

<?php
$query = "INSERT INTO category(cat_name, cat_desc, cat_image)" .
"VALUES('$cname', '$cdesc','$cimage')";
mysql_query($query,$link)
or die("Couldn't add data to add to \"Category\" table:
".mysql_error($link));
mysql_close($link);
?>

This is how I insert into mysql..
but still i cudnt able to see the image...
Did i made any wrong...?
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: How to retrieve images from database

  #10  
Oct 16th, 2007
i have a problem with images on my server where the extension will change to uppercase when uploaded. some servers will not display the image if the extension in the database and the one in the folder are not the same.

also did you add the folder to the path. (/folder/image.jpg)
Last edited by kkeith29 : Oct 16th, 2007 at 11:51 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC