I am trying to display an image using javascript from mysql table and also using php. I have a table named ci_images
and has a fields id, ci_ID, ciCode, Title, image
. After getting the rows using the code sql statement below, I want to display it using javascript. But i am not getting the right result on this code. It always returns an object in Console
of the browser (image). Please see code below
FIELDS:
id - int
ci_ID - int
ciCode - VarChar
Title - VarChar
image - LongBlob
PHP:
<?php
include_once('pConfig.php');
if (!isset($cID)){
$cID = filter_input(INPUT_GET, "cIDs");
}
if (!isset($ciCODe)){
$ciCode = filter_input(INPUT_GET, "ciCodes");
}
$stmt = $db->prepare("SELECT * FROM ci_images WHERE ci_ID = ? AND ciCODe = ?");
$stmt->bind_param('is', $cID , $ciCode);
$stmt->execute();
$result = $stmt->get_result();
if (!$result) {
printf("Error: %s\n", mysqli_error($db));
exit();
}
$json = mysqli_fetch_all($result, MYSQLI_ASSOC);
echo json_encode($json);
?>
JAVASCRIPT:
function previewImages(cID){
var ciCode = window.localStorage.getItem('ciCode');
var xdata = ({'cIDs': cID, 'ciCodes': ciCode });
$.ajax({
type: 'GET',
url: '../back_php_Code/pPrevImages.php',
dataType: 'json',
data: xdata,
contentType: 'application/json; charset=utf-8',
success: function (response) {
var cells = eval(response);
alert(JSON.stringify(cells));
for (var i=0; i < cells.length ; i ++){
$('#iSet').append('<div class="col-lg-4 col-sm-6">'
+ '<div class="thumbnail">'
+ '<div class="thumb">'
+ '<a href="..\files\assets\images\gallery-grid\1.png" data-lightbox="9" data-title="' + + '">'
+ '<img src="'+ + '" alt="" class="img-fluid img-thumbnail">'
+ '</a>'
+ '</div></div></div>');
}
},
error: function (error) {
console.log(error);
}
});
}
Return on Console.
Can someone help me to do the trick for this, I am stuck on this.
Thanks and Regards
Also, I have found something similar, but it does not work because , it only uses php and html. I think. Again Thanks
Link: