我被下面的代码卡住了...根据我的理解,下面的代码应该显示在数据库中创建的所有行数据...但是我只得到1行数据,结果我的产品页面上只有一种产品。 。 请帮忙...

<?php
include 'core/database/connect.php';
include 'core/includes/listhead.php';
$dynamiclist = "";
$sql = mysql_query("SELECT * FROM `index` ORDER BY price1 LIMIT 2");
$hotelcount = mysql_num_rows($sql);
if($hotelcount > 0) {
    while($row = mysql_fetch_array($sql)) {
    $id             = $row['index_id'];
    $pic            = $row['main_pic'];
    $country        = $row['country1'];
    $destination    = $row['destination1'];
    $price          = $row["price1"];
    $dynamiclist    = '<div class=/"offset-2/">
                        <div class="col-md-4 offset-0">
                            <div class="listitem2">
                                <a href="" data-footer="A custom footer text" data-title="A random title" data-gallery="multiimages" data-toggle="lightbox"><img src="'. $pic .'" alt=""/></a>
                                <div class="liover"></div>
                                <a class="fav-icon" href="#"></a>
                                <a class="book-icon" href="details.html"></a>
                            </div>
                        </div>
                        <div class="col-md-8 offset-0">
                            <div class="itemlabel3">
                                <div class="labelright">
                                    <img src="images/filter-rating-5.png" width="60" alt=""/><br/><br/><br/>
                                    <img src="images/user-rating-5.png" width="60" alt=""/><br/>
                                    <span class="size11 grey">18 Reviews</span><br/><br/>
                                    <span class="green size18"><b>'. $price .'</b></span><br/>
                                    <span class="size11 grey">Avg/Night</span><br/><br/><br/>
                                    <form action="http://demo.titanicthemes.com/travel/details.html">
                                     <button class="bookbtn mt1" type="submit">Book</button>
                                    </form>
                                </div>
                                <div class="labelleft2">
                                    <b>'. $country .'</b><br/><br/><br/>
                                    <p class="grey">
                                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec semper lectus. Suspendisse placerat enim mauris, eget lobortis nisi egestas et.
                                    Donec elementum metus et mi aliquam eleifend. Suspendisse volutpat egestas rhoncus.</p><br/>
                                    <ul class="hotelpreferences">
                                        <li class="icohp-internet"></li>
                                        <li class="icohp-air"></li>
                                        <li class="icohp-pool"></li>
                                        <li class="icohp-childcare"></li>
                                        <li class="icohp-fitness"></li>
                                        <li class="icohp-breakfast"></li>
                                        <li class="icohp-parking"></li>
                                        <li class="icohp-pets"></li>
                                        <li class="icohp-spa"></li>
                                    </ul>

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="offset-2"><hr class="featurette-divider3"></div>';
    }
} else {
    $dynamiclist = 'We Do Not Have Any Hotel Listed in This City';
}
?>
<?php echo $dynamiclist ?>
<?php include 'core/includes/listfooter.php'; ?>

最佳答案

你有两个问题

您的数据库查询仅限于2个项目(尽管这不能解释您目前遇到的1个问题)

删除LIMIT 2将解决此问题

其次

 $dynamiclist    = '<div class=/"offset-2/">


“ =”符号表示您每次都将其设置为内容。

很好,除非您在while循环外回显它

在您的while循环中回显它或将其更改为

$dynamiclist    .= '<div class=/"offset-2/">


注意。=->将项目添加到字符串的末尾。

希望能有所帮助

10-08 04:41