sanjay sanjay - 3 months ago 7
MySQL Question

How can i display image from mysql to table using php

Here is my code-

<?php
$con = mysql_connect('db', 'table', 'p/w');
if (!$con) {
die('Could not connect: ' . mysql_error()); }
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM computers WHERE KEYWORDS='Computers,Desktops'");
echo "<table border='1' width='100%' >";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['NAME'] . "</td>";
echo "<td>" . $row['MANUFACTURER'] . "</td>";


I want to display image from db stored as path here in one of the columns

echo "</tr>"; }
echo "</table>";
mysql_close($con);
?>


can anyone help? thanks

Answer
<?php 
$con = mysql_connect('db', 'table', 'p/w'); 
if (!$con) { die('Could not connect: ' . mysql_error()); } 
mysql_select_db("db", $con); 
$result = mysql_query("SELECT * FROM computers WHERE KEYWORDS='Computers,Desktops'"); 
echo "<table border='1' width='100%' >"; 
    while($row = mysql_fetch_array($result)) { 
        echo "<tr>";
        echo "<td>" . $row['NAME'] . "</td>"; 
        echo "<td>" . $row['MANUFACTURER'] . "</td>";
        echo "<td><img src='folder_name/".$row['image_name']."'></td>";
        echo "</tr>"; 
    }
echo "</table>";
mysql_close($con);
?>

folder_name=Name of the folder where image is saved
image_name=field name of the image in your table name computers

Comments