Devarajan Sekaran
Devarajan Sekaran

Reputation: 67

php code not working inside html

I am trying to display an image. I have fetched my URL from the db storage. And i have used the php variable inside the image tag. But the code does'nt display any image .

what is the problem? exactly!

this is my code below

  <?php $db =& JFactory::getDBO();

            $query88=$sql = "SELECT file_url_thumb FROM fs01_virtuemart_medias WHERE virtuemart_media_id=1 LIMIT 0, 30 ";

            $result88 = mysql_query($query88) or die(mysql_error());

      ?><img src="<?php while($row = mysql_fetch_array($result88)){
            echo $row['file_url_thumb'];
            echo "<br />";
            } ?>" border="0" style="border: 0; vertical-align: top;" />

Upvotes: 0

Views: 212

Answers (3)

Basic Bridge
Basic Bridge

Reputation: 1911

use this

 <?php
$db = &JFactory::getDBO();

$query88 = "SELECT file_url_thumb FROM fs01_virtuemart_medias WHERE virtuemart_media_id=1 LIMIT 0, 30 ";

$result88 = mysql_query( $query88 ) or die( mysql_error() );

    while($row = mysql_fetch_array($result88)){ 
                echo '<img src="'.$row['file_url_thumb'].'" style=" border="0" style="border: 0; vertical-align: top;"/>';
                echo '</br>';
                }
                ?>

Upvotes: 0

Peon
Peon

Reputation: 8030

<?php

$db = &JFactory::getDBO();

$query88 = "SELECT file_url_thumb FROM fs01_virtuemart_medias WHERE virtuemart_media_id=1 LIMIT 0, 30 ";

$result88 = mysql_query( $query88 ) or die( mysql_error() );

while( $row = mysql_fetch_array( $result88 ) ) {
    echo '<img src="' . $row[ 'file_url_thumb' ] . '" border="0" style="border: 0; vertical-align: top;" /><br />';
}

?>

Upvotes: 0

Quentin
Quentin

Reputation: 944530

You are looping over your results and putting them all (each followed by a <br /> inside the src attribute of an img tag. It seems highly unlikely that that won't 404.

You probably want something more like:

<ul>
  <?php while($row = mysql_fetch_array($result88)){ ?>
    <li><img src="<?php echo htmlspecialchars($row['file_url_thumb']); ?>" /></li>
  <?php } ?>
</ul>          

(With some CSS from an external stylesheet to apply your presentation).

Upvotes: 1

Related Questions