If statement for navigation bar

Hi,

I am building a left navigation bar with about 10 categories.

I need an IF statement within the below if statement that identifies when a particular category is clicked:


if(isset($_GET['category'])) {
 $selcat = $_GET['category'];
}

I am using this code. Which then helps create the navigation bar when clicked as so:


if(isset($selcat)) {
  echo "<a href='product.php?category=".$selcat."'>".$cats[$selcat]."</a>";
  unset($cats[$selcat]); //Gets rid of it for later.
  $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat);
  while($row = mysql_fetch_array($res)) {
   echo "<a href='product.php?productname=".$row['productid']."'>".$row['name']."</a>";
  }
}

The problem is if people click accessories I DO NOT want the links to read


"<a href='product.php?productname=".$row['productid']."'>".$row['name']."</a>";

as there is a few levels to the accessory navigation. For instance, rather than a list of products, there is first a list of manufacturers.

What I need is to do is further develop the first bit of code:


if(isset($_GET['category'])) {
 $selcat = $_GET['category'];
}

How can I get this to identify: IF $_GET[‘category’] = 8 then $selcataccessory=something different
else as normal ($selcat= $_GET[‘category’]:wink:

Then I can change the code that writes the navigation to recognise something different using isset. And alter the $res function also.


if(isset($selcataccessory)) {
  echo "<a href='product.php?category=".$selcat."'>".$cats[$selcat]."</a>";
  unset($cats[$selcat]); //Gets rid of it for later.
  $res = mysql_query("SELECT ANOTHER TABLE FROM products WHERE categoryid = ".$selcataccessory);
  while($row = mysql_fetch_array($res)) {
   echo "<a href='ACCESSORY.php?ACCESSORYSUBMENU=".$row['ACCESSORYid']."'>".$row['name']."</a>";
  }
}

So I think it is just the first bit of code that needs to be altered. How do I get the if statement added to the if statement to identify category 8 and change the selcat if this is the case!?!? Simple, probably, but I am stuck.

Matt.

You’ve… pretty much spelled it out exactly there.

(Generalized) IF format:
if (condition) {
True Statements;
} else {
False Statements;
}

Keep in mind that the conditional operator for equals to is == (or === if you’re being type-specific).

OK - Thanks - I’ve done that.

I was surprised that ‘or’ functions need stating exactly.

if (condition) must be if ($selcat==8 or $selcat==9)

NOT

if($selcat==8 or 9)

Now I know,

Matt.

Well, think of it as seperate sentences.
IF:
Selcat == 8 //Okay, that’s a test i can do.
OR
9 // Uh…