2014-03-26 55 views
-2

正試圖爲我的作業創建一個小型網站,並且卡在一個頁面中。實際上,我的代碼不工作,因爲沒有顯示任何內容,也沒有顯示錯誤。任何幫助,將不勝感激。在此先感謝..數據未從數據庫中顯示

<?php 
include ("masterzone/php/mysqli.php"); 

if ($stmt = $db->prepare("SELECT tbl_name FROM listing_title where listing_title_ID=?")) { 
    $tpe = $_GET['type']; 
    $stmt->bind_param("i", $tpe); 
    $stmt->execute(); 
    $stmt->bind_result($tbl_name); 
    $stmt->fetch(); 

    if ($stmt1 = $db->prepare("SELECT Name,Address,Phone,Email,Location,Time,Website,Photo1,Date_Published,Rating FROM $tbl_name where categories_ID=?")) { 
     $cat1 = $_GET['cat']; 
     $stmt1->bind_param("i", $cat1); 
     $stmt1->execute(); 
     $stmt1->bind_result($Name, $Address, $Phone, $Email, $Location, $Time, $Website, $Photo1, $Date_Published, $Rating); 
     $stmt1->fetch(); 
     ?> 
     <div id="loop_listing_taxonomy" class="list" > 
      <div class="post listing-11323 "> 
       <img src="images/<?php echo $Photo1; ?>" alt="" title="" /> 
       <div class="entry"> 
        <!--start post type title --> 
        <div class="listing-title"> 
         <h2 itemprop="name" class="entry-title"><?php echo $Name; ?></h2> 
         <div class="listing_rating"> 
          <div class="directory_rating_row"><span class="single_rating"> 
          <?php 
           for ($x = 1; $x <= $Rating; $x++) { 
            echo '<img src="images/rating-on.png" alt="" />'; 
           } 
          ?> 
          </span></div> 
         </div> 
         <p class="phone"><?php echo $Phone; ?></p><p class="address"><?php echo $Address; echo $Location; ?></p><p class="time"><?php echo $Time; ?></p> 
        </div> 
       </div> 
      </div> 
     </div> 
     <?php 
     $stmt1->close(); 
    } 

    $stmt->close(); 
} 
?> 
+0

您需要提供更多信息。開始檢查你的錯誤日誌... –

+0

檢查你的connexion和Mysql錯誤日誌或Apache ... – Portekoi

+0

添加echo'workin'在包含之前,將include更改爲require_once,創建臨時值並存儲查詢結果,以及var_dump它。基本上,嘗試隔離導致問題 – Dimitri

回答

0

你不能嵌套的mysqli準備的語句......我覺得你的意思有第二查詢while語句...

嘗試是這樣的:

<?php 
include ("masterzone/php/mysqli.php"); 

if ($stmt = $db->prepare("SELECT tbl_name FROM listing_title where listing_title_ID=?")) { 
    $tpe = $_GET['type']; 
    $stmt->bind_param("i", $tpe); 
    $stmt->execute(); 
    $stmt->bind_result($tbl_name); 
    $stmt->fetch(); 
    $stmt->free_result(); 
    $stmt->close(); 

    if ($stmt1 = $db->prepare("SELECT Name,Address,Phone,Email,Location,Time,Website,Photo1,Date_Published,Rating FROM $tbl_name where categories_ID=?")) { 
     $cat1 = $_GET['cat']; 
     $stmt1->bind_param("i", $cat1); 
     $stmt1->execute(); 
     $stmt1->bind_result($Name, $Address, $Phone, $Email, $Location, $Time, $Website, $Photo1, $Date_Published, $Rating); 
     while($stmt1->fetch()){ 
      ?> 
      <div id="loop_listing_taxonomy" class="list" > 
       <div class="post listing-11323 "> 
        <img src="images/<?php echo $Photo1; ?>" alt="" title="" /> 
        <div class="entry"> 
         <!--start post type title --> 
         <div class="listing-title"> 
          <h2 itemprop="name" class="entry-title"><?php echo $Name; ?></h2> 
          <div class="listing_rating"> 
           <div class="directory_rating_row"><span class="single_rating"> 
           <?php 
            for ($x = 1; $x <= $Rating; $x++) { 
             echo '<img src="images/rating-on.png" alt="" />'; 
            } 
           ?> 
           </span></div> 
          </div> 
          <p class="phone"><?php echo $Phone; ?></p><p class="address"><?php echo $Address; echo $Location; ?></p><p class="time"><?php echo $Time; ?></p> 
         </div> 
        </div> 
       </div> 
      </div> 
      <?php 
     } 
     $stmt1->free_result(); 
     $stmt1->close(); 
    } 
} 
?> 
+0

非常感謝您的答案。它的工作原理,但問題是它不檢索所有的數據,它只是檢索一個數據,我們不能用一個循環(例如:while循環)來準備語句嗎? – Shubhum

+0

@Shubhum我用一段時間的語句更新了代碼! –

+0

非常感謝你..上帝保佑..;) – Shubhum