PHP图像库的行

时间:2015-03-04 12:29:19

标签: php image row gallery

我在图片库上工作,我的上传和删除过程确实有效,但现在我想将图像放在行中,而不是将它们放在彼此之下。这是我的输出代码,我不知道从哪里开始,有人能告诉我正确的方向吗?

为了更具体一点,我想在它“跳下”并开始一个新行之前连续放置4个图像。我想我需要某种循环吗?

<?php

include 'includes/db_connect.inc.php';


$result = mysqli_query($link, "SELECT * FROM gallery");

while ($row = mysqli_fetch_array($result)) {
$filename = $row['filename'];
$title = $row['title'];
$id = $row['id'];

    echo '<p>
    <a href="images/'.$filename.'" title="'.$title.'" >
        <img src="images/'.$filename.'" title="'.$title.'" width="300"/>
    </a></p>';

    if (isset($_SESSION['user']))
            echo '<a href="gallery_delete.php?id='.$id.'" onclick="return confirm(\'Are you sure you wish to delete the image?\')">Delete Image</a>';

            echo '<hr>';
}

        if (isset($_SESSION['user'])) 
        { 
        ?>
        <p><a href="gallery_form.php?">Add new image</a></p>
        <?php
        }
        ?>

2 个答案:

答案 0 :(得分:0)

尝试简单的CSS

    echo '<p style="display:inline;">
<a href="images/'.$filename.'" title="'.$title.'" >
    <img src="images/'.$filename.'" title="'.$title.'" width="300"/>
</a></p>';

由于<p>是块级标记。它们会自动放在彼此之下。

答案 1 :(得分:0)

未经测试的代码..如果它不起作用请尝试自己使用表

<?php
     include 'includes/db_connect.inc.php';
    $result = mysqli_query($link, "SELECT * FROM gallery");
    ?>
    <table>
   <?php
    while ($row = mysqli_fetch_array($result)) {
    $filename = $row['filename'];
    $title = $row['title'];
    $id = $row['id'];
    ?>
       <tr><td>
        <a href="images/'.$filename.'" title="'.$title.'" >
            <img src="images/'.$filename.'" title="'.$title.'" width="300"/>
        </a></td>
    <td>
<?php
        if (isset($_SESSION['user']))
 ?>
<a href="gallery_delete.php?id='.$id.'" onclick="return confirm(\'Are you sure you wish to delete the image?\')">Delete Image</a>
   </td></tr>
<?php
    }
?>
    </table>
<?php
            if (isset($_SESSION['user'])) 
            { 
            ?>
            <p><a href="gallery_form.php?">Add new image</a></p>
            <?php
            }
            ?>