Jump to content

Echoing an image as a variable


fat creative

Recommended Posts

I am trying to call in image from my database and it's just not working. I get no image.  My page is at www.FatCreative.com/GFF and the images that aren't displaying are at the bottom of the page. When I code the name of the image, it works fine, but when I try to change the image name to the variable, I get a blank box.  I'm sure it's something so simple.  I've had tried dozens of different variations and I am either getting nothing or an error message.  I have confirmed the variable name is showcase_image all lowercase.

 

This is my code:

    echo "<table cellspacing=\"15\">\n";

  while($row = mysql_fetch_assoc($result))

  {

      extract($row);

      echo "<tr><td>";

      echo "<img src=\"$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >";

      echo "  $prop_title<br />";

      echo "$prop_desc<br />";

      echo "<a href=\"showdetails.php?id_number=$id_number\"><div align=\"right\">View Details</div></a>";

      echo "</td></tr>\n";

  }

 

echo "</table>\n";

 

Does anyone have any ideas? I am just learning PHP (and loving it!) but some of these things are so frustrating.

Link to comment
Share on other sites

Well, you are going to have to paste more code then that. Where are your queries, what are the names of your DB tables? Try something like this. Just use it as a guideline. Considering I do not know the names of your database tables, make sure to replace the appropriate values.

 

$query = "SELECT * FROM TABLENAME";
$result = mysql_query($query) or die(mysql_error() . "<pre>$query</pre>");

echo "<table cellspacing=\"15\">";

while($row = mysql_fetch_array($result))
{
      echo '<tr><td>';
      echo '<img src="'.$row[showcase_image].'" style="width: 100px; height: 100px; vertical-align: middle; padding-right: 5px;" >';
      echo $row[prop_title].'<br />'.$row[prop_desc].'<br />';
      echo '<div style="text-align: right;"><a href="showdetails.php?id_number='.$row[id_number].'">View Details</a></div>';
      echo "</td></tr>";      
}

echo "</table>";

 

If this has solved your problem, please do not forget to mark the topic as solved. You will find the button on the bottom left of the page.

 

Take care.

Link to comment
Share on other sites

My apologies. The newbieness prevents me from knowing what is too little to copy vs too much.

 

This is the query part of the code:

$query = "SELECT * FROM GFF WHERE featured_site = 'yes'";

$result = mysql_query($query)

    or die ("Couldnt execute query");

 

I did copy / paste what you suggested, but it still didn't return any images.

 

This was the original code and the page is at www.fatcreative.com/GFF:

<?php

  echo "<table cellspacing=\"15\">\n";

  while($row = mysql_fetch_assoc($result))

  {

      extract($row);

      echo "<tr><td>";

      echo "<img src=\"$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >";

      echo "  $prop_title<br />";

      echo "$prop_desc<br />";

      echo "<a href=\"showdetails.php?id_number=$id_number\"><div align=\"right\">View Details</div></a>";

      echo "</td></tr>\n";

  }

 

echo "</table>\n";

?>

 

I just can't see why this isn't working. 

 

Thank you again very much for any suggestions!

Link to comment
Share on other sites

if you check your img src it looks like this

 

Georgia Farm & Forest\Bartow\Bartow 9520\Images\IMGP1202.JPG

 

I would suggest just having the name of the image in your database and then do this

 

echo "<img src=\"images/$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >";

 

or wherever your images are located

 

also it's much cleaner if you remove all those echo and do something like

 

<table cellspacing="15">
<?
   while($row = mysql_fetch_assoc($result))
   {
      extract($row);
?>
     <tr><td>
     <img src="<?=$showcase_image?>" width="100" height="100" align="middle" >
      <?=$prop_title?>

      <?=$prop_desc?>
      <a href="showdetails.php?id_number=<?=$id_number?>"><div align="right">View Details</div></a>";
     </td></tr>
<?
   }
?>
</table>

 

but that's just a matter of personal taste ;)

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.