Fetch and display image from a MySQL database in div id
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Trying to display an image within a div id tag, the path of which is fetched from a MySQL db.

The information is extracted from the db using the following code:

$query = $db->query("SELECT distribution.id, distribution.summary, distribution. retail, .... WHERE......;

$rowCount = $query->num_rows;
    if($rowCount > 0){
    $result = $query->fetch_assoc();
    $result['id'] = utf8_encode($result['id']);
    $result['summary'] = utf8_encode($result['summary']);
    $result['comment'] = utf8_encode($result['comment']);
    $result['retail'] = utf8_encode($result['retail']);
    $result = '';
$data['result'] = $result;
$data['rowCount'] = $rowCount;
echo json_encode($data);

The image is not stored in the db, but stored as a path (e.g. 0.png, 1.png etc.), and is to be displayed on another page as a div id:

Also would like for a default img to be shown unless a different one selected.

I think you should show the HTML instead.
alixaxel 19 days ago
@limm007 ? You there?
SilverHood Apps 18 days ago
Hello ??
SilverHood Apps 16 days ago
Thank you
SilverHood Apps 15 days ago

Crowdsource coding tasks.

1 Solution

Hi, to do that you need an ajax call, for simplicity i've used jQuery its easy.
As per your db schema, just pass the value of the idt (which is your id in database) you wish to display in the div

Retrieve the id on PHP by:

$idd = $_REQUEST['idt'];

Html: https://codeshare.io/5OeoXg

(This link expires every 24hrs, hence i need to update it everyday. kindly revert asap)

Let me know hows that..

ps: i've stored images in image directory and entery in db is image/1.png for id 100

output image with directory structure: https://ibb.co/fqcdf8
SilverHood Apps 19 days ago