4 Replies - 1422 Views - Last Post: 04 April 2012 - 06:58 AM Rate Topic: -----

#1 Coolest_gal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Unable to retrieve image from database

Posted 31 March 2012 - 07:27 AM

I get a blank page showing URL of the page and image is not retrieved.I know that its a good idea to store images in a database but I have no other option.
<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "*********";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table."); 
$result =mysql_query( 'select * from product');
header("Content-type: image/jpeg");
print "<table>"; 
while ($row = mysql_fetch_array( $result ))
{  
?>
<tr>
<td width ="60" height ="60">
<?php  echo $row['image'];?>
</td>
</tr>
<?php
}
?>
 
 






Is This A Good Question/Topic? 0
  • +

Replies To: Unable to retrieve image from database

#2 Coolest_gal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Unable to retrieve image from database

Posted 31 March 2012 - 07:56 AM

*its not a good idea to store images in a database
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Unable to retrieve image from database

Posted 31 March 2012 - 08:35 AM

Something like this.
Was This Post Helpful? 1
  • +
  • -

#4 jonesa01   User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Re: Unable to retrieve image from database

Posted 02 April 2012 - 02:57 AM

The main option I can think of is to have two seperate files one which has the table and the other which displays the image.

<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "*********";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table."); 
$result =mysql_query( 'select * from product');
print "<table>"; 
while ($row = mysql_fetch_array( $result ))
{  
?>
<tr>
<td width ="60" height ="60">
<img src="images.php?id=<?=$result["id"];?>">
</td>
</tr>
<?php
}
?>



image.php
<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "*********";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table."); 
$result =mysql_query( 'select * from product where id = '.$_GET["ID"].' LIMIT 1;');
$result = mysql_fetch_array($reult);
header("Content-type: image/jpeg");
echo $result['image'];
?>



This code should do it.

This post has been edited by jonesa01: 02 April 2012 - 02:57 AM

Was This Post Helpful? 0
  • +
  • -

#5 Coolest_gal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Unable to retrieve image from database

Posted 04 April 2012 - 06:58 AM

^^Thanks! It worked great.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1