Php Code to display Images with text stored in Database (MySQL).


 Below Code is used to fetch images from Database and view it with combination of text and images..


 <?php
    // connection to database
include 'dbCnfig.php';
$sql = "SELECT  id, image, descrip
FROM    image
LIMIT   0, 10";
$result = mysql_query($sql) or die(mysql_error());
echo '<table border=1 cellpadding=12 cellspacing=21>';
while($row = mysql_fetch_assoc($result)) {
echo <<<HTML
<tr>
<td>{$row['id']}</td>
<td>{$row['descrip']}</td>
<td><img src="View_img.php" height="20" width="200"/></td>
</tr>
HTML;
}
echo '</table>';
?>
---------------------------------------------------------------------------------------------------

View_img.php
<?php
// connection to database
include 'dbCnfig.php';
$qury = "SELECT * FROM image WHERE id=2";
$res = mysql_query($qury);
if (mysql_num_rows($res) == 0) {
echo "No Data in DB";
}
else {
while($row = mysql_fetch_array($res)){
$ids = $row['id'];
$images = $row['image'];
}
}
//Header ("Content-type: application/msword");
//Header ("Content-type: text/HTML");
Header ("Content-type: text/plain");
//Header ("Content-type: image/jpg");
echo $images;
?>

Comments