单行的详细信息按钮[PHP,MYSQL]

时间:2017-03-25 07:36:53

标签: php mysql database post

目前我有一些PHP代码返回每行的div视图,其中包含图像和一些文本但现在我想要我可以通过单击按钮从该行转到详细页面但我没有&知道如何在PHP中做到这一点有人可以帮助我吗?

以下代码用于查看所有行

$servername = "localhost";
$username = "root";
$password = "1234";
$dbname = "Motion";
$Teller = 0;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT id, camera, filename, frame, file_type, time_stamp, event_time_stamp FROM security ".$WhereBetween."group by time_stamp";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     //echo "<table><tr><th>camera</th><th>filename</th><th>frame</th><th>file_type</th><th>time_stamp</th><th>event_time_stamp</th></tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
       echo "<!-- thumbnail image wrapped in a link -->
     <div class='Blok'>
     <a href='#img".$teller."' class='Afbeelding'>
        <img src='".str_replace("/var/www/html","",$row["filename"])."' class='thumbnail'>
     </a>
     <div class='Tekst'>
       <h3>Motion Detection</h3>
       <p>
         Camera ID: ".$row["camera"]."<br>
         Timestamp: ".$row["time_stamp"]."<br>
         Filename:".str_replace("/var/www/html/img/","",$row["filename"])."
       </p>
     //Here i want the button to go to detail page
     </div>
     </div>";

2 个答案:

答案 0 :(得分:0)

我会写这个答案,但我很忙。我回答了类似的问题。请检查此How to get same row data when click on button using PHP

所以你做的很简单。在while循环中,将主键的值放在模态onclick上。 这将链接到您的引导视图模式

如果没有帮助,请发表评论

答案 1 :(得分:0)

请在下面的代码中指定$ WhereBetween。

$servername = "localhost";
        $username = "root";
        $password = "1234";
        $dbname = "Motion";
        $Teller = 0;
        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
             die("Connection failed: " . $conn->connect_error);
        } 
        $sql = "SELECT id, camera, filename, frame, file_type, time_stamp, event_time_stamp FROM security ".$WhereBetween."group by time_stamp";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
             //echo "<table><tr><th>camera</th><th>filename</th><th>frame</th><th>file_type</th><th>time_stamp</th><th>event_time_stamp</th></tr>";
             // output data of each row
             while($row = $result->fetch_assoc()) {
               echo "<!-- thumbnail image wrapped in a link -->
             <div class='Blok'>
             <a href='#img".$teller."' class='Afbeelding'>
                <img src='".str_replace("/var/www/html","",$row["filename"])."' class='thumbnail'>
             </a>
             <div class='Tekst'>
               <h3>Motion Detection</h3>
               <p>
                 Camera ID: ".$row["camera"]."<br>
                 Timestamp: ".$row["time_stamp"]."<br>
                 Filename:".str_replace("/var/www/html/img/","",$row["filename"])."
               </p>
             //Here i want the button to go to detail page
              <button onclick=\"window.location='http://example.com/index?id=".$row["ID"]."'\">Kill</button>
             </div>
             </div>";
          }
    }