【问题标题】:Horizontal looping mysql inside div tagdiv标签内的水平循环mysql
【发布时间】:2014-11-26 13:41:12
【问题描述】:

有人可以帮我制作类似于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>

【问题讨论】:

  • 你希望每三个项目水平然后在接下来的三个项目下方等等,对吗??
  • 你是否包含了引导 css?
  • 添加一个css命令(float:left;)到容器div
  • @S.Pols 是的,我包括引导程序
  • @sandeepKumar 是的,这就是我想要的。但它似乎需要 foreach() 语句。我不知道我该怎么做:(

标签: php html mysql css loops


【解决方案1】:

试试这个。如果 .thumbnail 已经在你的 css 中有 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>

【讨论】:

  • 你的屏幕分辨率是多少?
  • 可能是空间不足的问题。如果将图像宽度更改为 50 会发生什么?
  • 不,由于某种原因,它终于可以工作了。这只是css问题,谢谢你的帮助:)
猜你喜欢
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-05
  • 2020-09-30
  • 1970-01-01
相关资源
最近更新 更多