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)

Junior Member

10+ Year Member

joined:Oct 11, 2005
votes: 0


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)

New User

10+ Year Member

joined:May 29, 2005
votes: 0

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)

Senior Member from MT 

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 1, 2003
votes: 0

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)

Junior Member

10+ Year Member

joined:Oct 11, 2005
votes: 0

Cheers guys,

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

Thanks again.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members