Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

Is this PHP code correct? Show region if two recordsets are empty...

This code works but I want a blessing from a real PHP programmer. I use Dreamweaver and want to show a div if TWO recordsets are empty instead of the usual one. So I just added another set of parenthesis and the "AND" operator.

Original code produced by Dreamweaver:

<?php if ($totalRows_rsCategories == 0) { // Show if recordset empty ?>
  <div>Sorry! No information is available.</div>
  <?php } // Show if recordset empty ?>

The code I wrote to add another recordset. Is this correct?

<?php if (($totalRows_rsCategories == 0) AND ($totalRows_rsPremium == 0))  { // Show if recordset empty ?>
  <div>Sorry! No information is available.</div>
  <?php } // Show if recordset empty ?>


Thanks, Gary

0
WebStudioWest
Asked:
WebStudioWest
2 Solutions
 
v2MediaCommented:
Ya, it's valid but could use an operand with higher precidence '&&' .
<?php if ($totalRows_rsCategories == 0 && $totalRows_rsPremium == 0)  { // Show if recordset empty ?>
  <div>Sorry! No information is available.</div>
  <?php } // Show if recordset empty ?>

Open in new window

0
 
St1ckmanCommented:
v2Media is right, that's the best way to do it.

Here's a reference for you about logic operators:

&& is AND
|| is OR
> is Greater Than
< is Less Than
>= is Greater than or Equal to
<= is Less Than or Equal to
!= is NOT Equal to
! is NOT

and for ! (NOT) on it's own, you have to put it before the variable:

<?php if (!$totalRows_rsCategories && !$totalRows_rsPremium)  { // Show if recordset empty ?>

That will check if there's any data for $totalRows_rsCategories and $totalRows_rsPremium, if both do not have any data at all, it will display your message that there is no information available.
You can use that too, example below for your reference:


<?php if (!$totalRows_rsCategories && !$totalRows_rsPremium)  { // Show if recordset empty ?>
  <div>Sorry! No information is available.</div>
  <?php } // Show if recordset empty ?>

Open in new window

0
 
WebStudioWestAuthor Commented:
Excellent! Thanks for the info.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now