12 Replies - 4569 Views - Last Post: 21 April 2011 - 05:15 AM Rate Topic: -----

#1 tharu901  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 13-March 11

retrieve an image in php

Posted 13 March 2011 - 07:05 AM

how to retrieve a image from mysql database?using PHP..
Is This A Good Question/Topic? 0
  • +

Replies To: retrieve an image in php

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: retrieve an image in php

Posted 13 March 2011 - 07:09 AM

Well, that would all depend on how you're SAVING the image in your database.
Was This Post Helpful? 1
  • +
  • -

#3 tharu901  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 13-March 11

Re: retrieve an image in php

Posted 13 March 2011 - 07:23 AM

View Posttharu901, on 13 March 2011 - 07:05 AM, said:

how to retrieve a image from mysql database?using PHP..

<?php
$con=mysql_connect("localhost", "root", "");
mysql_select_db("mobile_hut",$con);
$query = "SELECT * FROM news";
$result = mysql_query($query);

while ($r=mysql_fetch_array($result))
{
$pic = $r['image'];
echo '<img src="$pic">'  ;
}
mysql_close($con);
?> 





that is code i use it for image retrieval but it does not show ihe image..
Was This Post Helpful? -1
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: retrieve an image in php

Posted 13 March 2011 - 07:28 AM

Again, I asked how you SAVED it in the DB, not how you're retrieving it!
Was This Post Helpful? 1
  • +
  • -

#5 tharu901  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 13-March 11

Re: retrieve an image in php

Posted 13 March 2011 - 08:23 AM

View PostJackOfAllTrades, on 13 March 2011 - 07:28 AM, said:

Again, I asked how you SAVED it in the DB, not how you're retrieving it!


I stored it mysql database as a text format.as below...

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: retrieve an image in php

Posted 13 March 2011 - 08:55 AM

Are you storing the actual image as TEXT or are you saving the PATH to the image?

There are eleven billion tutorials on this available to you through Google. I would suggest you find one and use it.
Was This Post Helpful? 0
  • +
  • -

#7 tharu901  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 13-March 11

Re: retrieve an image in php

Posted 13 March 2011 - 09:30 AM

View PostJackOfAllTrades, on 13 March 2011 - 08:55 AM, said:

Are you storing the actual image as TEXT or are you saving the PATH to the image?

There are eleven billion tutorials on this available to you through Google. I would suggest you find one and use it.



yes i stored the path of image as text....
ya definitely there are billions of tutorials i follow the few of these but i cant satisfy with it...please can you help me even give a simple tutorials as a link.....
Was This Post Helpful? 0
  • +
  • -

#8 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: retrieve an image in php

Posted 13 March 2011 - 03:16 PM

Are you storing the full path? Just the file name? What about extension?

What I mean is:

Suppose your image is called dream_in_code_rulez.jpg and is stored in /images/.

Are you storing:
  • dream_in_code_rulez
  • dream_in_code_rulez.jpg
  • images/dream_in_code_rulez.jpg


If you are only storing the file name, with out an extension, you would need to modify your code like so:

echo "<img src=images/'$pic'.jpg />";



Also please note that I have closed the image tag correctly.

Also are you getting any errors?

This post has been edited by KingCuddles: 13 March 2011 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,142
  • Joined: 08-June 10

Re: retrieve an image in php

Posted 13 March 2011 - 03:41 PM

View PostKingCuddles, on 13 March 2011 - 11:16 PM, said:

Also please note that I have closed the image tag correctly.

correctly in the sense that it is invalid HTML because you definitely do not use XHTML?
Was This Post Helpful? 0
  • +
  • -

#10 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: retrieve an image in php

Posted 13 March 2011 - 03:49 PM

maybe you got wrong with saving the image..which is the most important because how will u able to retrieve if it is not there or the file doesn't exist. please check if you include the directory name,file name, and also the extension,. u can get all of this at your upload script. be guided..
Was This Post Helpful? 0
  • +
  • -

#11 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: retrieve an image in php

Posted 13 March 2011 - 03:50 PM

Sorry my bad I thought it was valid for HTML as well as XHTML :(

I always validate XHTML Strict anyway :D

Thanks for spotting that Dormilich

This post has been edited by KingCuddles: 13 March 2011 - 03:52 PM

Was This Post Helpful? 0
  • +
  • -

#12 neil_12s  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-April 11

Re: retrieve an image in php

Posted 20 April 2011 - 10:26 PM

Well Thanks for all the suggestion. I have saved the image in a table named "children" in a mysql database. It is saved as a link (url) example

http://www.............ages/Childrens/sn3.jpg

What I want to know is how to retrieve this link either to a variabale or as the link itself and show the image in a web page. What I am trying to do is to show the images like in a slide show. I am working with PHP.

Hope you can help me.

Thanks
Wilfred.

This post has been edited by neil_12s: 20 April 2011 - 10:28 PM

Was This Post Helpful? 0
  • +
  • -

#13 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: retrieve an image in php

Posted 21 April 2011 - 05:15 AM

neil_12s, you received an answer in your own topic. Please don't resurrect older topics with a "me too" post!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1