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
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>";
	 ?>

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.