2017-10-27 1 views
0
<?php 
    $directory = "img/media/"; 
    $files = glob($directory. '/*.{jpg,jpeg,png,gif}', GLOB_BRACE); 

//Loop through images 
foreach($files as $image) 
{ 
    echo' 
     <div class="card animation_one p-0 m-0"> 
      <img class="card-img" src="'. $image .'" alt="Card image"> 
      <button type="button" class="btn btn-primary btn-lg btn-center bg-offBlue t-pureWhite" data-toggle="modal" data-target="#exampleModal" onclick="">Bekijk</button> 
     </div> 

     <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 
      <div class="modal-dialog" role="document"> 
      <img class="img-fluid" src="'. $image .'" alt="Card image"> 
      </div> 
     </div> 
    '; 
} 
?> 

Meine Frage ist für einige Leute sehr einfach, aber ich habe gerade mit der Programmierung begonnen, also brauche ich etwas Hilfe dabei. Wenn ich eine foreach Schleife habe, woher weiß ich und zeige das vorgewählte (in diesem Fall img) an, um im modalen Popup zu zeigen?php foreach Artikel wählen

+0

sollten Sie Javascript verwenden (jquery vorgeschlagen) letzte Auswahl des Benutzers zu erkennen und damit etwas tun Objekt. Ich denke ich konnte nicht verstehen was du willst – snoopcommands

+0

Das ist ** nicht ** eine PHP Frage. es ist eine html/css Frage. Sie müssen das richtige HTML-Markup für ein modales Popup-Fenster drucken ... PHP wird auf dem Server verarbeitet, aber auf der Client-Seite erscheinen "Popups". –

Antwort

0

diesen Bruder versuchen,

mit Hilfe von foreach

//Loop through images 
$count=0; 
foreach($files as $image) 
{ 
    echo' 
     <div class="card animation_one p-0 m-0"> 
      <img class="card-img" src="'. $image .'" alt="Card image"> 
      <button type="button" class="btn btn-primary btn-lg btn-center bg-offBlue t-pureWhite" data-toggle="modal" data-target="#exampleModal_'.$count.'" onclick="">Bekijk</button> 
     </div> 

     <div class="modal fade" id="exampleModal_'.$count.'" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 
      <div class="modal-dialog" role="document"> 
      <img class="img-fluid" src="'. $image .'" alt="Card image"> 
      </div> 
     </div> 
    '; 
    $count+=1; 
} 

mit for-Schleife

for($i=0;$i<count($files);$i++) 
{ 
    $image=$files[$i]; 
    echo' 
     <div class="card animation_one p-0 m-0"> 
      <img class="card-img" src="'. $image .'" alt="Card image"> 
      <button type="button" class="btn btn-primary btn-lg btn-center bg-offBlue t-pureWhite" data-toggle="modal" data-target="#exampleModal_'.$i.'" onclick="">Bekijk</button> 
     </div> 

     <div class="modal fade" id="exampleModal_'.$i.'" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 
      <div class="modal-dialog" role="document"> 
      <img class="img-fluid" src="'. $image .'" alt="Card image"> 
      </div> 
     </div> 
    '; 
} 
+0

Ich weiß es zu schätzen Danke, es hat funktioniert :) –