"> How to display images from database? - Forums

Forums

How to display images from database?

rkloots 18 Apr, 2012
Hi,

What is wrong in code below?

In MySql table "catalog" a field "image" indicates path and imagename, extension is jpg. images are stored in a joomla directory.
I've tried
<? php 
$img_path="/path/images/" ;
$query = "SELECT id, image FROM catalog";
$db->setQuery($query);
foreach ( $roww as $r ) {
//   $imag = table.image;
//   $pictur=$img_path.$imag ; 
//   header("Content-Type:image/jpg");  
//   echo "<img src="$pictur"  width=120 height=90>"; 
   echo "<img src="$r[image]"  width=120 height=90>"; 
  }
?>
GreyHead 19 Apr, 2012
Hi rkloots,

[list=a]
  • You haven't initialise the $db object (which may not be a problem)

  • You haven't executed the MySQL query

  • You have errros in the quotes in the echo line

  • You need a valid URL, not a folder path. I can't tell from your code which is being created.
  • [/list:o]
    <?php
    $img_path = JURI::base()."path/images/" ;
    $db =& JFactory::getDBO();
    $query = "
        SELECT id, image 
            FROM catalog;
    ";
    $db->setQuery( $query );
    $roww = $db->loadAssocList();
    foreach ( $roww as $r ) {
        echo "<img src='$r[image]' width='120' height='90' />";
    }
    ?>




    Bob
    This topic is locked and no more replies can be posted.