<?php
$query=mysql_query("SELECT model_no,images1 FROM nokia");
echo"<div>";
    while ($img = mysql_fetch_array($query))
    {
        echo $img[0];
        echo "<img src = cms/pages/images/".$img[1].">";
        }
echo"</div>";

?>

what is actually wrong in my code.. its not displaying images($img[1]) but it displays the content 'model_no' ie. $img[0]. plz any sugesstion would be greatly helpful...

Recommended Answers

All 5 Replies

Here is a good approach for displaying an image from a MySQL database using PHP.

<?php
$query = $mysqli->query("SELECT model_no,images1 FROM nokia");
$fetch = $query->fetch_object();
$img = $fetch->imgname;
?>
<html>
    <body>
        <img width="100%" height="100%" src="images/<?php echo $img; ?>">
    </body>
</html>
Member Avatar for diafol

@sush

I can't see much wrong with your code. Have a look at the underlying html (view source) in your browser. Does the image src attribute show the value you expect it to?

//EDIT

Strike that - you've messed up the double quotes

echo "<img src = cms/pages/images/".$img[1].">";

should be

echo "<img src = 'cms/pages/images/{$img[1]}'>";

yes, like diafol pointed out, change $img[0] to $img[1]

<?php 
$query=mysql_query("SELECT model_no,images1 FROM nokia");
  while ($img = mysql_fetch_array($query))

  @$mod_no=$img['model_no'];
  @$image=$img['images1'];
  echo $mod_no."\n";
  ?>
  <img src="cms/pages/images/<?php echo $image; ?>" width="218" height="172">
  <?php
  }

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.