2016-07-31 6 views
-1

Ich machte eine PHP-Datei, die Daten aus MySQL-Datenbank abfragt und Ergebnisse in HTML-Tabelle bringt. Ein Feld in Datenbank enthält Verknüpfungen zu Datei (en). Ein oder mehrere, getrennt durch Kommas. Alles funktioniert gut. (Verwendung: GROUP_CONCAT(CONCAT(filename)) in SQL-Abfrage. Jetzt der schwierige Teil. Ich versuchte zu verwenden Bootstrap Modals. Mein Hauptziel ist - wenn ich den Knopf klicke, werde ich kleines Popup mit Verbindungen innerhalb. Aber ich bekomme nur einen Link von der .. erste Ergebnis in einer Tabelle wenn ich die tabel sortieren irgendwie - gleiche passiert Hier ist die kleine Ausgabe aus der Tabelle, die ich jetzt haben:HTML-Tabelle in PHP mit Popup

8 Company 1  Address 12-11/12, City 2017-04-16 12/022 Link  
9 Company 2  P. Address 19-M1,City 2020-03-31 15/039 Link  
10 Company 3  Address 1,City 2017-04-05 12/015 Link,Link,Link,Link 

So, das Ziel ist: Taste, wenn ich auf Es erscheint ein Popup mit Links darin Irgendwelche Hinweise, wie man das erreicht? Vielleicht zusätzliche Abfrage von ID oder so?

+0

Ich würde eine PHP-Funktion erstellen retrive die Links der ID der Auflistung (oder was auch immer es sein sollte), und rufen diese Funktion mit der ID (des Elements, von dem Button geklickt wird) über einen Ajax-Aufruf, wenn das Modell angezeigt wird. – Paul

+0

Das kann für Sie interessant sein: http://StackOverflow.com/Questions/18378720/bootstrap-3-with-remote-modal – Paul

Antwort

-1

Vielleicht so etwas?

if(isset($_POST['button'])) { 
    $result = mysqli_query($conn,"SELECT * FROM table WHERE address='.$address' "); 
    echo "<table>"; 
    while($row = mysqli_fetch_array($result)) 
    { 
    echo "<tr>"; 
    echo '<td> <a href="' . $row['link1'] . '">Link1</a> </td>'; 
    echo '<td> <a href="' . $row['link2'] . '">Link2</a> </td>'; 
    echo '<td> <a href="' . $row['link3'] . '">Link3</a> </td>'; 
    echo "</tr>"; 
    } 
    echo "</table>"; 
} 

Wenn Sie nicht wissen, wie viele Links, die Sie brauchen, um Echo werden, müssen Sie eine zweite Schleife

+0

'. $ Adresse' sieht aus wie ein Tippfehler. '$ address' ist nicht definiert und sucht nach den OP-zu-SQL-Injektionen. – chris85

1

Test es funktionierte

<?php 
$arr = [ 
    ["Company 1", "Address 1,City", "2017-04-05", "12/015", "Link"], 
    ["Company 3", "Address 1,City", "2017-04-05", "12/015", "Link,Link,Link,Link"] 
]; 
?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>Example of Bootstrap 3 Modals</title> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $(".btn").click(function(){ 
     $("#myModal").modal('show'); 
    }); 
}); 
</script> 
<style type="text/css"> 
    .bs-example{ 
     margin: 20px; 
    } 
</style> 
</head> 
<body> 
<div class="bs-example"> 
    <!-- Button HTML (to Trigger Modal) --> 
    <a href="#" class="btn btn-lg btn-primary">Launch Demo Modal</a> 

    <!-- Modal HTML --> 
    <div id="myModal" class="modal fade"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 

       <table> 
        <tr> 
        <th>name</th> 
        <th>address</th> 
        <th>date</th> 
        <th>data</th> 
        <th>links</th> 
        </tr> 
        <tr> 
         <?php foreach ($arr as $value): ?> 
         <tr> 
          <td><?= $value[0]; ?></td> 
          <td><?= $value[1]; ?></td> 
          <td><?= $value[2]; ?></td> 
          <td><?= $value[3]; ?></td> 
         <td> 
         <?php if (strpos($value[4], ',') == false AND ! empty($value[4])): ?> 
          <a href="<?= $value[4]; ?>">link name</a> 
         <?php else: ?> 
          <?php $links = explode(',', $value[4]); ?> 
          <?php foreach ($links as $link): ?> 
          <a href="<?= $link; ?>">link name</a> 
          <?php endforeach; ?> 
         <?php endif; ?> 
         </td> 
         </tr> 
         <?php endforeach; ?> 
       </table> 
       <table> 

       </table> 
      </div> 
     </div> 
    </div> 
</div> 
</body> 
</html>          
+0

Ich werde versuchen, es nach Bedarf zu ändern und zu verwenden. Vielen Dank. – Jaur