homepage Welcome to WebmasterWorld Guest from 54.205.99.71
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Over 100 switch cases!
Is there a better way?
one_mind




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

Hi,

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]

 

JamShady




msg:1290286
 9:24 am on Oct 18, 2005 (gmt 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.

killroy




msg:1290287
 9:36 am on Oct 18, 2005 (gmt 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.

one_mind




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

Cheers guys,

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

Thanks again.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved