0
How can i fetch new images everytime from database,,? when I click on submit btn
want to fetch new images everytime on same page,, whenever click on submit btn,
7 ответов
+ 1
Addy Do this using fetch API
const img = document.getElementById('img');
fetch(phpcodetogetimage)
.then(response => response.blob(); )
.then(myBlob => {
let url = URL.createObjectURL(myBlob);
img.src = url;
});
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
The PHP is as follows
<?php
$pdo = new pdo(....your db details);
$result = $pdo -> query(....your sql query);
$row = $result -> fetch (PDO::FETCH_ASSOC); echo $row["imageData"];
?>
+ 1
do you have an attempt code for us to give opinion on?
+ 1
Okay, let me try this
0
Are the images stored as BLOB in your database or did you just store their file path? Please answer this question so that I will know the next thing to suggest.
0
Blob
0
Addy Do this using fetch API
const img = document.getElementById('img');
fetch(phpcodetogetimage)
.then(response => response.blob(); )
.then(myBlob => {
var url = URL.createObjectURL(myBlob);
img.src = objectURL;
});
0
Addy Yeah do. Also I added a sample php code to fetch the data from database