Jump to content

retrieving images from database


average american

Recommended Posts

I am trying to retieve images from my database mysql using php and am unable to get them to display.

 

this is my code

 

//listing results

$sql = "SELECT listings.* FROM listings";

$result = mysql_query($sql);

$numrows = mysql_num_rows($result);

require("header.php");

 

echo "<table cellpadding ='5'>";

echo "<tr>";

echo "<h1>Available Properties</h1>";

echo "<th>Image</th>";

echo "<th>Item</th>";

echo "<th>Bed/Bath/Garage</th>";

echo "<th>Rent</th>";

echo "<th>Description</th>";

echo "</tr>";

if($numrows == 0) {

echo "<tr><td colspan=4>No Items!</td></tr>";

}

else {

while($row = mysql_fetch_assoc($result)) {

 

$imagesql = "SELECT * FROM images WHERE

listing_id = ". $row['id']." LIMIT 1";

$imageresult = mysql_query($imagesql);

$imagenumrows = mysql_num_rows($imageresult);

 

echo "<tr>";

if($imagenumrows == 0) {

echo "<td>No Image</td>";

}

else {

$imagerow = mysql_fetch_assoc($imageresult);

echo "<td>" .$imageresult["content"] . "</td>";

}

echo "<td>";

echo "<a href='listingdetails.php?id="

. $row['id'] . "'>" . $row['address'] . "</a>";

$_SESSION['USERID'] == $row['user_id'];

 

echo "</td>";

 

$BBGsql = "SELECT * FROM listings WHERE listings.id=" . $row['id'] . ";";

$BBGresult = mysql_query($BBGsql);

$BBGrow = mysql_fetch_assoc($BBGresult);

$BBGnumrows = mysql_num_rows($BBGresult);

 

echo "<td>";

echo $BBGrow['bed'] . " ⁄ ";

echo $BBGrow['bath'] . " ⁄ ";

echo $BBGrow['garage'];

echo "</td>";

 

echo "<td>" . $config_currency;

echo $BBGrow['rent'];

echo "</td>";

 

echo "<td>";

echo $BBGrow['description'];

echo "</td>";

 

i am in quite the bind as i only have a couple of days to get this done.  I have my database setup and the info is BLOB.

 

 

Link to comment
https://forums.phpfreaks.com/topic/69111-retrieving-images-from-database/
Share on other sites

Try This

 

<?php
//listing results
   $sql = "SELECT listings.* FROM listings";
   $result = mysql_query($sql);
   $numrows = mysql_num_rows($result);
require("header.php");

echo "<table cellpadding ='5'>";
echo "<tr>";
echo "<h1>Available Properties</h1>";
   echo "<th>Image</th>";
   echo "<th>Item</th>";
   echo "<th>Bed/Bath/Garage</th>";
   echo "<th>Rent</th>";
   echo "<th>Description</th>";
echo "</tr>";
if($numrows == 0) {
   echo "<tr><td colspan=4>No Items!</td></tr>";
}
else {
   while($row = mysql_fetch_assoc($result)) {
   
      $imagesql = "SELECT * FROM images WHERE
   listing_id = ". $row['id']." LIMIT 1";
      $imageresult = mysql_query($imagesql);
      $imagenumrows = mysql_num_rows($imageresult);
      
      echo "<tr>";
         if($imagenumrows == 0) {
            echo "<td>No Image</td>";
         }
         else {
            $imagerow = mysql_fetch_assoc($imageresult);
            echo "<td><img src=".$imageresult["content"]." width="100" height="100" border="0" /></td>";
         }
         echo "<td>";
         echo "<a href='listingdetails.php?id="
   . $row['id'] . "'>" . $row['address'] . "[/url]";
         $_SESSION['USERID'] == $row['user_id'];
                  
         echo "</td>";
         
         $BBGsql = "SELECT * FROM listings WHERE listings.id=" . $row['id'] . ";";
         $BBGresult = mysql_query($BBGsql);
         $BBGrow = mysql_fetch_assoc($BBGresult);
         $BBGnumrows = mysql_num_rows($BBGresult);
         
         echo "<td>";
         echo $BBGrow['bed'] . " ⁄ ";
         echo $BBGrow['bath'] . " ⁄ ";
         echo $BBGrow['garage'];
         echo "</td>";
         
         echo "<td>" . $config_currency;
         echo $BBGrow['rent'];
         echo "</td>";
         
         echo "<td>";
         echo $BBGrow['description'];
         echo "</td>";
	 ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.