user7404503
user7404503

Reputation:

If field == null display else don't

My recordset is:

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);

and the code I'm using to display the record is:

<?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)); ?>

This all works fine if a record exists but if there is no record, a 'link' is available to click even though it's not visible.

I have tried <?php if ($totalRows_rsOtherServices['subMenuID'] === Null) { ?>, <?php if ($totalRows_rsOtherServices['subMenuID'] > 0) { ?>, <?php if ($totalRows_rsOtherServices['subMenuID'] == true) { ?>, <?php if ($totalRows_rsOtherServices['subMenuID'] == false) { ?>but to no avail.

I know nothing about programming and even less about PHP so I'm not even sure is I'm going in the right direction.

I need to get rid of the 'invisible link'.

Upvotes: 1

Views: 96

Answers (2)

user7404503
user7404503

Reputation:

OK, I've figured it out.

Instead of using $((totalRows_rsOtherServices['subMenuID']) > 0), I changed it to (($row_rsOtherServices) > 0). This did the trick.

However, if I use the while (($row = mysqli_fetch_assoc($rsOtherServices)))... as suggested, even if there is a record, it doesn't display.

At this moment in time I'm not going to worry to much about that but will investigate it in the future.

Upvotes: 0

Moustafa Elkady
Moustafa Elkady

Reputation: 670

Because you are using do ... while, use while only.

Try

<?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>
<? } ?>

Upvotes: 3

Related Questions