div标签内的水平循环mysql

时间:2014-11-26 13:41:12

标签: php html mysql css loops

有人可以帮助我制作与this网站类似的内容循环吗? 我尝试使用while()构造并且它是垂直循环的。它似乎没有使用表,我认为这个页面使用缩略图。

我真正需要的是项目将循环每3个项目,这是我编写并垂直显示的代码。

<div class="container">

<?php

    include "config/database.php";

    $sql = "SELECT * FROM anidata";
    $query = mysql_query($sql);

    if ($query > 0) {
?>

<div class="col-sm-6 col-md-4" style="float: left;">
<?php
    while($row = mysql_fetch_array($query)){
        $image = $row['image'];
        $title = $row['title'];
        $genre = $row['genre'];
        $start = $row['start'];
        $schedule = $row['schedule'];
        $description = $row['description'];
?>

<div class="row">
    <div class="thumbnail" >
        <div>
            <img src="admin/<?php echo $row['image']; ?>" width="194" height="272">
        </div>

        <div class="caption">
            <span id="teks" style="font-size:18px;"><?php echo $title; ?></span>
            <div class="line-title">
                </div>
                <div class="description">
                    <span style="font-size:12px;"><?php echo $description; ?></span>
                </div>

                <div class="genre">
                    <span><?php echo $genre; ?></span>          
                </div>                  
            </div>             
        </div>
    <?php } ?>
    </div>
<?php } ?>
</div>

1 个答案:

答案 0 :(得分:0)

试试这个。如果您的css中.thumbnail已有float:left;,则可以删除style attr。

<div class="container">

<?php

    include "config/database.php";

    $sql = "SELECT * FROM anidata";
    $query = mysql_query($sql);

    if ($query > 0) {
?>

<div class="col-sm-6 col-md-4" style="float: left;">


<div class="row">

    <?php
        while($row = mysql_fetch_array($query)){
            $image = $row['image'];
            $title = $row['title'];
            $genre = $row['genre'];
            $start = $row['start'];
            $schedule = $row['schedule'];
            $description = $row['description'];
    ?>
    <div class="thumbnail" style="float:left;">
        <div>
            <img src="admin/<?php echo $row['image']; ?>" width="194" height="272">
        </div>

        <div class="caption">
            <span id="teks" style="font-size:18px;"><?php echo $title; ?></span>
            <div class="line-title">
                </div>
                <div class="description">
                    <span style="font-size:12px;"><?php echo $description; ?></span>
                </div>

                <div class="genre">
                    <span><?php echo $genre; ?></span>          
                </div>                  
            </div>             
        </div>
    <?php } ?>
    </div>
<?php } ?>
</div>