2017-03-18 22 views
1

我的記錄是:如果場==否則返回null顯示不

mysqli_select_db($KCC, $database_KCC); 
$query_rsOtherServices = "SELECT pagecontent.mainMenuID, mainmenu.mainMenuLabel, pagecontent.subMenuID, submenu.subMenuLabel, pagecontent.contentID, pagecontent.contentTitle FROM submenu RIGHT JOIN (mainmenu RIGHT JOIN pagecontent ON mainmenu.mainMenuID = pagecontent.mainMenuID) ON submenu.subMenuID = pagecontent.subMenuID WHERE pagecontent.mainMenuID = 1 AND pagecontent.subMenuID IS NULL"; 
$rsOtherServices = mysqli_query($KCC, $query_rsOtherServices) or die(mysqli_error()); 
$row_rsOtherServices = mysqli_fetch_assoc($rsOtherServices); 
$totalRows_rsOtherServices = mysqli_num_rows($rsOtherServices); 

和我使用的顯示記錄的代碼是:

<?php do { ?> 
<li><a href="familyservices.php?idVal=<?php echo $row_rsOtherServices['contentID']; ?>"><h4><?php echo $row_rsOtherServices['contentTitle']; ?></h4></a></li> 
<?php } while ($row_rsOtherServices = mysqli_fetch_assoc($rsOtherServices)); ?> 

如果這一切工作正常記錄存在,但如果沒有記錄,即使不可見,也可以點擊「鏈接」。

我試過<?php if ($totalRows_rsOtherServices['subMenuID'] === Null) { ?>,<?php if ($totalRows_rsOtherServices['subMenuID'] > 0) { ?><?php if ($totalRows_rsOtherServices['subMenuID'] == true) { ?>,<?php if ($totalRows_rsOtherServices['subMenuID'] == false) { ?>,但無濟於事。

我對編程一無所知,甚至對PHP的瞭解甚少,所以我甚至不確定我是否會朝着正確的方向前進。

我需要擺脫'隱形鏈接'。

回答

2

因爲您使用的是do ... while,請僅使用while

嘗試

<?php while (($row = mysqli_fetch_assoc($rsOtherServices))) { ?> 
    <li> 
     <a href="familyservices.php?idVal=<?php echo $row['contentID']; ?>"> 
      <h4><?php echo $row['contentTitle']; ?></h4> 
     </a> 
    </li> 
<? } ?> 
+1

正確。也許加入'foreach'看起來如何的代碼。 – trincot

+1

對不起,但我認爲只有正確的一個,試試吧。 –

+0

如果我使用它,即使有要顯示的記錄,它也不會顯示任何內容。事實上,由於最後一行中的'',我得到一個錯誤。如果我將其更改爲'',則會刪除錯誤。 – MartySmartyPants

0

OK,我已經想通了。

取而代之的是使用$((totalRows_rsOtherServices['subMenuID']) > 0),我將其更改爲(($row_rsOtherServices) > 0)。這個伎倆。

但是,如果我按照建議使用while (($row = mysqli_fetch_assoc($rsOtherServices)))...,即使有記錄,也不顯示。

在這個時候,我不會擔心太多,但將在未來進行調查。

相關問題