How can i fetch new images everytime from database,,? when I click on submit btn | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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,

18th May 2020, 4:03 AM
Addy
Addy - avatar
7 Réponses
+ 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"]; ?>
18th May 2020, 6:19 AM
Ore
Ore - avatar
+ 1
do you have an attempt code for us to give opinion on?
18th May 2020, 5:11 AM
Gordon
Gordon - avatar
+ 1
Okay, let me try this
18th May 2020, 6:29 AM
Addy
Addy - avatar
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.
18th May 2020, 5:41 AM
Ore
Ore - avatar
0
Blob
18th May 2020, 6:09 AM
Addy
Addy - avatar
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; });
18th May 2020, 6:19 AM
Ore
Ore - avatar
0
Addy Yeah do. Also I added a sample php code to fetch the data from database
18th May 2020, 6:41 AM
Ore
Ore - avatar