Jump to content

[SOLVED] display image from DB link


coupe-r

Recommended Posts

I have links to my files in my DB.  ex. /apache/htdocs/img/test.jpg

 

When I echo the information, I just get an empty square where the image should be.

 

Now, I believe it will be the headers, but i have tried header('Content-type: image/jpeg') but it does not work.

 

Any other suggestions?

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

if($count < 17)
{
	$page = '<a href = "products.php">Page 1</a>';
}
	elseif($count < 37)
	{
		$page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
		$page .= '<a href = "products.php?page=2">Page 2</a>';
	}


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
if( (($i % 4) == 0) && ($i != 0) )
{
	echo '</tr><tr>';
}

echo '<td width="25%" height="150" align="center">' . '<img src="' . $row['prod_img'] . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';

$i++;

}

echo '</tr>';
echo '<table>';

?>

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

if($count < 17)
{
	$page = '<a href = "products.php">Page 1</a>';
}
	elseif($count < 37)
	{
		$page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
		$page .= '<a href = "products.php?page=2">Page 2</a>';
	}


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
if( (($i % 4) == 0) && ($i != 0) )
{
	echo '</tr><tr>';
}

echo '<td width="25%" height="150" align="center">' . '<img src="' . $row['prod_img'] . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';

$i++;

}

echo '</tr>';
echo '<table>';

?>

 

Try this, it's untested.

 

<?php
$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

   if($count < 17)
   {
      $page = '<a href = "products.php">Page 1</a>';
   }
      elseif($count < 37)
      {
         $page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
         $page .= '<a href = "products.php?page=2">Page 2</a>';
      }


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
   if( (($i % 4) == 0) && ($i != 0) )
   {
      echo '</tr><tr>';
   }

   /**
   * I'm assuming all your image's reside in the /img directory.
   */
   echo '<td width="25%" height="150" align="center">' . '<img src="img/' . substr($row['prod_img'], strrpos("/", $row['prod_img']) + 1, strlen($row['prod_img'])) . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';
   
   $i++;
   
}

echo '</tr>';
echo '<table>';

?>

Link to comment
Share on other sites

Images are requested by browsers using a URL. URL's are relative to your document root folder. Based on what you have shown, you have a file system path stored as part of what you are calling a link.

 

Your document root folder appears to be apache/htdocs. Therefore, a valid URL (relative to your document root folder) would be http://yourdomain.com/img/test.jpg (using an actual domain) or http://localhost/img/test.jpg (on your local host development system.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.