图像作为按钮打开使用模态

时间:2018-04-01 07:48:03

标签: php html css mysql twitter-bootstrap

我正在显示数据库中的图像。图库应为(n行)x 3列类型,其中每个网格将具有小图像。单击图像,其大尺寸将显示在bootstrap-modal中。我该怎么做呢?无法绕开。可以点击图像,但是没有动作发生。这是我试过的代码:
    

        $conn = new mysqli("localhost","root","","yomadsdata");
        $sql = "select * from photos";
        $result = $conn->query($sql);

        if($result->num_rows > 0)
        {
            $c = 0;
            while($row = $result->fetch_assoc())
            {
                $path = $row["photo_path"];
                $image_id = $row["id"];
                echo "<button type='button' data-toggle='modal' data-target='#mymodal'>
                        <div id='photoframe'>
                          <img id='photoId' src='photos/$path' alt='$path'>
                        </div>
                      </button>";

                echo '
                <div class="modal fade" id="myModal" role="dialog">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <img src="photos/'.$path.'" alt="'.$path.'" height="300" width="400">
                    </div>
                  </div>
                </div>';

                $c++;
                if($c == 3)
                {
                    echo "<br>";
                    $c == 0;
                }
            }
        }
        else{
            echo "No photos in the database.";
        }

        $conn->close();

0 个答案:

没有答案