-1

My question is regarding this answer. Bootstrap open image in modal

How can I display images that's src comes from MySQL database?

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
JayV
  • 35
  • 6

1 Answers1

0

simply echo the img source from the database.

<?php 
  if(isset($_POST['profile_id'])){
     var uid=$_POST['profile_id'];
     $result->query("SELECT profile FROM user WHERE uid=$uid");
     $row=$result->fetch_array();
     die(json_encode($row));
  }
?>

HTML:

<a href="#" class="pop">
  <img src="" style="width: 400px; height: 264px;">
</a>

Jquery Part:

$.post("ajax.php",{profile_id:1},function(response){
   if(response){
     var profileImg=JSON.parse(response);
         profileImg=profileImg[0].profile;
         $('.pop img').attr('src','http://example.com/image/'+profileImg);
         $('.pop').modal('show');
   }
});
Sarath Kumar
  • 1,136
  • 1
  • 18
  • 41
  • Sarath I know the PHP part. I want to know how to display images in modal using jquery and bootstrap. – JayV Jul 13 '17 at 12:44