If statement in another if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

If statement in another if statement

Post by Milan »

I have this :

Code: Select all

<? if ($_GET['cat']=="all"){
require_once('Connections/allcat.php');
}
else
require_once('Connections/singlecat.php');
?>

that code will check if user wants to view all categories or a single product category BUT now i have another problem i need also to check if record count is 0 and in that case just echo "recordset is empty". so what is the correct way yo implement that second if?

Code: Select all

if ($totalRows_product=="0") {....
or there is another way to solve the problem



thanks
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

not sure I understand it right but would that work for you?

Code: Select all

if($recordcount == 0)
{
}
elseif($_GET['cat']=="all")
{
}
else
{
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: If statement in another if statement

Post by Christopher »

Code: Select all

<?php
if ($totalRows_product > 0) {
    if ($_GET['cat']=="all"){
        require_once('Connections/allcat.php');
    } else {
        require_once('Connections/singlecat.php');
    }
} else {
    require_once('Connections/norecords.php');
}
?>
Or:

Code: Select all

<?php
if ($_GET['cat']=="all"){
    if ($totalRows_product > 0) {
        require_once('Connections/allcat.php');
    } else {
        require_once('Connections/norecords.php');
    }
} else {
    require_once('Connections/singlecat.php');
}
?>
(#10850)
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

thanks!

Post by Milan »

works great for cat=all but it does not check if single category is empty or not ( my bad i should have mentinoned that i have another reecordset also for single categories)

other one ( single cat)

$totalRows_singleproject


thanks guys!
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Re: If statement in another if statement

Post by PrObLeM »

Code: Select all

<? 
	if ($_GET['cat']=="all"){
		if( $totalRows_product ) {
			require_once('Connections/allcat.php');
		} else {
			//all cat empty
		}
	} else {
		if( $totalRows_singleproject ) {
			require_once('Connections/singlecat.php');
		} else {
			//single cat empty
		}
	}
?>
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

GREAT !!!!

In my code i was missing a }

YOU GUYS ROCK!
Post Reply