Multiple case or switch commands in php?

Posted by kitenski on Stack Overflow See other posts from Stack Overflow or by kitenski
Published on 2010-06-02T11:47:15Z Indexed on 2010/06/02 11:54 UTC
Read the original article Hit count: 224

Filed under:
|
|

Good Afternoon,

I am trying to assign some variables to a listing which has a main category and a subcategory. This works fine for most of the variables, however in each sub category there are some fields which are other.

ie Main Category 1 has sub category database, development and other Main Category 2 has sub category email, internet and other Main Category 3 has sub category graphics and other.

So my first case statement is as follows which works fine.

switch ($main_cat)
 {
    case "Main Category 1":
      $main="79";
        break;
    case "Main Category 2":
      $main="83";
        break;
    case "Main Category 3":
      $main="87";
        break;
}

However I am struggling as to how to handle other.

This stops the whole page loading with no error message

switch ($second_cat)
 {
    case "Database":
      $second="145";
        break;
    case "Development":
      $second="146";
        break;
    case "Other":
      if ($main_cat) == 'Main Category 1'  { $second="147";}
       break;
}

This doesn't work at all, second is not changed.

switch ($second_cat)
 {
    case "Database":
      $second="145";
        break;
    case "Development":
      $second="146";
        break;
    case "Other":
switch ($main_cat)
{
case "Main Category 1":
      $second="147";
        break;
}
}

© Stack Overflow or respective owner

Related posts about php

Related posts about case