Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Over 100 switch cases!

Is there a better way?



7:34 am on Oct 18, 2005 (gmt 0)

10+ Year Member


I started programming a way to list all my projects in a data base. Each project belongs to a category and a subcategory. All the code below is my implementation of only 3 categories and 1 subcategory. As you can see, it is starting to get out of hand :)

By the time i add all 10 categories and each subcategory having 10 more subcategories each, that will be over 100 switch cases and they are already starting to confuse me. I cant think of any other way to set this up. I dont know or want to learn oop and was hoping there would be a procedural way of handling it.

Is the way i am doing normal and should i just keep going or is there a better way?

Thanks :)

[edited by: coopster at 7:34 pm (utc) on Oct. 18, 2005]
[edit reason] removed code dump [/edit]


9:24 am on Oct 18, 2005 (gmt 0)

10+ Year Member

Yeah, the normal method is to store all the categories in some form of database (either an RDMS like MySQL, or even in an array with PHP) and use this information to then dynamically generate the list. It's not recommended to hand-write the entire list.


9:36 am on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Exactly. Also, most folks who help other folks won't read all that, so you might do a limited, html-poor sample case to make your point rather then pasting several pages of source.


10:00 am on Oct 18, 2005 (gmt 0)

10+ Year Member

Cheers guys,

I didn't expect anyone to read it, just making the point that my way is crap :)

Thanks again.


Featured Threads

Hot Threads This Week

Hot Threads This Month