Page 1 of 1

IF statements

Posted: Mon Jul 21, 2003 7:15 pm
by DuFF
Here is what I'm trying to do, its kind of confusing to explain.
Depending on how many subcategories the user is, I want to display links showing the higher subcategories. Here is an example of where a user could be:

Counter-Strike (category)
--------|
--------|----Weapons (subcat1)
-----------------|
-----------------|------USP (subcat2)

(I have all the subcategories recorded in a database.) The user shown above would have a url like this:
models.php?category=Counter-Strike&subcat1=Weapons&subcat2=USP. I want to show the following:

Counter-Strike >> Weapons >> USP

The problem is finding IF statements that will show the correct listing. Because if the user is in the Counter-Strike folder but not in any subcategories then subcat1 and subcat2 should not be shown. This should be shown:

Counter-Strike

Here is what I have so far, the problem is that 2 of the IF statements return true if subcat1 and subcat2 are both NULL.

Code: Select all

<?php
if ($subcat1=="" && $subcat2==""){echo $category;}
    if ($subcat1==""){echo "<a href='models.php?category=$category'>$category</a> >> $subcat1";}
    else {echo "<a href='models.php?category=$category'>$category</a> >> <a href='models.php?category=$category&subcat1=$subcat1'>$subcat1</a> >> $subcat2";}
?>
Maybe these links will help anyone that still does not understand:
http://members.lycos.co.uk/duff234/mode ... ter-Strike (this one doesnt work)
http://members.lycos.co.uk/duff234/mode ... t1=Weapons
http://members.lycos.co.uk/duff234/mode ... ubcat2=USP

Thanks for any help.

...

Posted: Mon Jul 21, 2003 7:21 pm
by kettle_drum
Try something like this:

Code: Select all

<?php

if($category){
   if(!$subcat){
      #echo category
   }else{
      if(!$subcat2){
         #echo category > subcat
      }else{
         #echo category > subcat > subcat2
      }
   }
}

?>

Posted: Mon Jul 21, 2003 7:39 pm
by Slippy
Maybe this would work?:

Code: Select all

if (($subcat1=="") && ($subcat2=="")){echo $category;}
Although I believe recursion would be the best bet -- it may be too complicated for your task.

Posted: Mon Jul 21, 2003 11:52 pm
by DuFF
Thanks a lot kettle_drum, works like a charm. :D