2014-01-05 111 views
0

我被困在下面的代碼...根據我的理解,下面的代碼應顯示在我的數據庫中創建的所有行數據...但即時只獲得1行數據在我的產品頁面上的結果只有一個產品...請幫助...查詢只返回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'; ?> 
+0

你覆蓋'$ dynamiclist'每次迭代 – Andomar

+0

和查詢包含'限制2'僅返回2行最多。 –

+0

請建議如何避免這個錯誤我是新來的PHP ...想知道如果你可以編輯上面的代碼... –

回答

0

你有兩個問題

你的數據庫查詢限制爲2項(雖然這並不能說明你此刻的1項問題)

消除限制2將解決此

其次

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

「=」號表示您每次都將其設置爲內容。

這是好的,除非你回聲它OUTSIDE while循環

要麼呼應它while循環內或將其更改爲

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

通知= - >,增加了項目的結束字符串。

希望幫助

+0

謝謝里奇... :) –

+0

沒問題 - 希望一切順利! –

0

更改

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

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

如果要加載所有行,請從查詢中刪除「LIMIT」。

+0

謝謝KutePHP :) –