tags:

views:

56

answers:

2

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;
}
}
A: 

Use a database, Luke.
Use a database.

Col. Shrapnel
Col. Shrapnel - I am writing the output to a database.....
kitenski
@kitenski I mean use a database to store all this structure
Col. Shrapnel
+2  A: 

Badly formed if statement:

if ($main_cat) == 'Main Category 1'  { $second="147";}

should be:

if ($main_cat == 'Main Category 1')  { $second="147";}

Also, you should put error_reporting(E_ALL); at the top of your script for debugging purposes.

karim79
+1 good catch..
mr.b
karim79 - thanks alot, that worked. The first lines of my script have error reporting on, but I still just saw a blank page.<?php error_reporting(E_ALL); ini_set("display_errors", 1); ?>
kitenski