从左到右显示图像php

时间:2016-09-21 08:53:44

标签: javascript php html mysql css

<table>
        <tr>
            <th>image</th>
        </tr>
            <?php 
                $query = "SELECT * FROM collage";
                $result = mysqli_query($con, $query);
                while($row = mysqli_fetch_array($result))
                {
                ?>
                    <tr>
                        <td><a href="img/collage/<?php echo $row['file'] ?>" target="_blank"><img src="img/collage/<?php echo $row['file'] ?>"></a></td>
                    </tr>
                <?php
                }
                ?>
    </table>
你好天才的程序员! 我上面的代码显示如下图像:

enter image description here

我希望它变成这样: enter image description here

2 个答案:

答案 0 :(得分:3)

<tr></tr>

中设置<?php ?>

试试这个

<table>
    <tr>
        <th>image</th>
    </tr>
     <tr>
        <?php 
            $query = "SELECT * FROM collage";
            $result = mysqli_query($con, $query);
            while($row = mysqli_fetch_array($result))
            {
            ?>

                    <td><a href="img/collage/<?php echo $row['file'] ?>" target="_blank"><img src="img/collage/<?php echo $row['file'] ?>"></a></td>

            <?php
            }
            ?>
    </tr>
</table>

答案 1 :(得分:0)

您当前正在循环表行。您需要一个表格单元格的内部循环才能获得您提到的表格设计。

以下是参考:http://www.w3schools.com/html/html_tables.asp

会是这样的:

<?php 
            $query = "SELECT * FROM collage";
            $result = mysqli_query($con, $query);
            while($row = mysqli_fetch_array($result))
            {
            ?>

                    <td><a href="img/collage/<?php echo $row['file'] ?>" target="_blank"><img src="img/collage/<?php echo $row['file'] ?>"></a></td>

            <?php
            }
            ?>