Problem when trying to retrieve image by name

  • joy1986joy
  • Novice
  • Novice
  • User avatar
  • Joined: Jul 04, 2010
  • Posts: 27
  • Status: Offline

Post November 30th, 2010, 3:20 am

I want to retrieve image from database without storing the image data. Just storing the image path I want to retrieve or show the image if anybody can help
Code: [ Select ]
<?php
//hear I will retrieve image path from database. For testing purpose I have given it manually.
$img_path="images/a.jpg";
//hear I will print the image.
echo "<img src='$img_path' />";

?>
  1. <?php
  2. //hear I will retrieve image path from database. For testing purpose I have given it manually.
  3. $img_path="images/a.jpg";
  4. //hear I will print the image.
  5. echo "<img src='$img_path' />";
  6. ?>


I also need to write some html in the same page.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 30th, 2010, 3:20 am

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post November 30th, 2010, 8:00 am

Are you basically asking how to connect to a database and retrieve information?
#define NULL (::rand() % 2)
  • joy1986joy
  • Novice
  • Novice
  • User avatar
  • Joined: Jul 04, 2010
  • Posts: 27
  • Status: Offline

Post November 30th, 2010, 10:53 pm

No. I am asking for displaying the image by calling it from the image folder. I don't want to store the image in the database. I want to store only the location of the image. Then I want to pass the image location by a php variable after retrieving it from database. So I have retrieve it. But I am not able to display it.
by this line:
Code: [ Select ]
echo "<img src='$img_path' />";
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post December 1st, 2010, 7:49 am

So the code in your last post does not display the image?

What value are you storing in the database? If the image isn't being displayed your probably not calling the image from the root of the domain, which in a lot of cases is what it needed.
#define NULL (::rand() % 2)
  • joy1986joy
  • Novice
  • Novice
  • User avatar
  • Joined: Jul 04, 2010
  • Posts: 27
  • Status: Offline

Post December 1st, 2010, 9:36 am

I am storing the image path. Like "images/abc.jpg"
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Feb 17, 2005
  • Posts: 1585
  • Status: Offline

Post December 1st, 2010, 10:39 am

Do this: http://www.w3schools.com/php/php_mysql_select.asp

PHP Code: [ Select ]
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("my_db", $con);
 
$result = mysql_query("SELECT src FROM images");
 
while($row = mysql_fetch_array($result))
  {
  echo '<img src="'.$row['src'].'" />';
  echo '<br />';
  }
 
mysql_close($con);
?>
  1. <?php
  2. $con = mysql_connect("localhost","peter","abc123");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7.  
  8. mysql_select_db("my_db", $con);
  9.  
  10. $result = mysql_query("SELECT src FROM images");
  11.  
  12. while($row = mysql_fetch_array($result))
  13.   {
  14.   echo '<img src="'.$row['src'].'" />';
  15.   echo '<br />';
  16.   }
  17.  
  18. mysql_close($con);
  19. ?>
There's no place like 127.0.0.1, badass part is now it's ::1
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post December 1st, 2010, 1:20 pm

Your going to need to store either the complete path to the image or at least add on the complete path.

If the images folder is at the root of your domain all you will have to do is add a slash infront /images/abc.jgg
#define NULL (::rand() % 2)
  • joy1986joy
  • Novice
  • Novice
  • User avatar
  • Joined: Jul 04, 2010
  • Posts: 27
  • Status: Offline

Post December 7th, 2010, 11:53 pm

Got the solution. thanks everybody for help. Now I can retrieve images from data base by their name.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.