Php 如果字段==null,则显示else don';T
我的记录集是:Php 如果字段==null,则显示else don';T,php,mysqli,dreamweaver,Php,Mysqli,Dreamweaver,我的记录集是: 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 (main
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更是一无所知,所以我甚至不确定我的方向是否正确
我需要去掉“不可见链接”。因为您正在使用
do。。。当
时,仅当时使用
试一试
好的,我已经弄明白了
我没有使用$(totalRows\u rsOtherServices['subnumuid'])>0)
,而是将其更改为($row\u rsOtherServices)>0)
。这就成功了
但是,如果我按照建议使用while($row=mysqli\u fetch\u assoc($rsOtherServices))…
,即使有记录,也不会显示
此时此刻,我不太担心这一点,但将来会对此进行调查。正确。也许可以添加
foreach
的代码。抱歉,但我认为虽然只有正确的代码,但请尝试。如果我使用此代码,即使有记录要显示,它也不会显示任何内容。事实上,由于最后一行中的
,我得到了一个错误。如果我将其更改为
,错误将被删除。
<?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>
<? } ?>