0
I am trying to create a modal window that will bring from a Mysql database only the final part of a URL of an image that is available on the internet (eg parte_final.png ) the problem is that I am not able to make the code work in concatenation, because I need to join the initial part of the URL (ex: http://www.algumsite=) the rest of the url that comes from the database.
First I have a query to DB to loop all the images that are stored with the respective URL s, to generate the various buttons each one must present a different image.
<?php
$sql = "SELECT * FROM imagens";
$conn = mysql_query($sql, $conecta);
while($row = mysql_fetch_assoc($conn))
{
?>
<a href="#" onClick={"$('#imgTag').attr('src', 'http://www.algumsite=<?php echo $row['img_url'];?>')"} type="button" class="btn btn-danger" data-toggle="modal" data-target="#imgModal">BUTTON</a>
<?php } ?>
<!-- Modal -->
<div class="modal fade" id="imgModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">ITEM</h4>
</div>
<div class="modal-body">
<img id="imgTag">
</div>
</div>
I don’t know if I explained myself well, but what I want to do is kind of weird, but it has to be anyway, concatenate the initial part of the url with the final part of the url that comes from DB by PHP.
Instead of calling the onclick() function on the button, I can consider examples of an external function by Jquery, but for in my case it is not necessary, thanks already for the possible help, I’m even stuck here!
Kaduamaral the code did not work, I click on the link and nothing happens, any more suggestions?
– Luis
You have to see why it didn’t work. There was an error on the @Luis console?
– KaduAmaral
Kaduamaral on the console had an error on this line of code: $('[data-toggle="modal-image"]'). on('click', Function(Event)' it says Uncaught Referenceerror: jQuery is not defined(Anonymous Function) @ jquery-ui.js:319
– Luis
@Luis, did you load the jQuery library? Make sure it is loaded correctly, before Bootstrap and jQuery-UI. I updated the code too.
– KaduAmaral
My head looks like this: <script type="text/javascript" src=".. /js/jquery-2.1.4.min. js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap3.3.5/js/bootstrap.min.js"></script> I changed the code and it didn’t work again, there’s no way you can publish the code running somewhere online to see what’s wrong?
– Luis
@Luis I noticed that the code you posted from the modal is missing close two tags, see if that’s why it didn’t work. I put the example there as you asked.
– KaduAmaral
Kaduamaral Just one more thing, as I center the image that appears in the modal window?
– Luis
Use CSS:
#imgTag { display:block; margin: 0 auto; }
or#imgModal .modal-body {text-align:center;}
@Luis– KaduAmaral