sanjay
sanjay

Reputation: 61

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

Upvotes: 0

Views: 34782

Answers (2)

sujal
sujal

Reputation: 1050

<?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

Upvotes: 3

sikas
sikas

Reputation: 5523

You can use the img element wherever you want to show the image.

echo "<img src='" . $row['image'] . "'>". You can also check img element for HTML or img element for HTML5

Upvotes: 0

Related Questions