SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there such thing as 'to many' switch statements?

    Just wondering if it's possible to have to many switch statements. As of now I have about 50.

    PHP Code:
     case 'num1':
      include(
    "./num1.php");
         break; 

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that there is a real limit, except maybe the memory of the server, but if you ask questions like this then you probably have some code design problems.
    Anyway, I might be able to guess what you're doing, so see if this code helps you.
    PHP Code:
    // Your available pages (can be generated out of a db table)
    $a_available = array('main' => 'index.php''guestbook' => 'guestbook.php''admin'  => 'admin/index.php');
    $s_default 'index.php'// The default page (if the parameter is invalid)

    include (isset($_GET['page']) && isset($a_available[$_GET['page']])) ? $a_available[$_GET['page']] : $s_default

  3. #3
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    When PHP says it is unable to allocate XXXX bytes out of the 16 MB allocated for the process, you have run into the limit of available switch statements.

    However, if you are finding that you are using a lot of switch statements in complex statements, you might want to re-evaluate your programming and breaking some of that up into functions to make your overall code more readable.
    Wayne Luke
    ------------


  4. #4
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay..cool...I'm still farily new to PHP so Gaheris I don't fully understand what your code means (any explanation would rock)...at any rate...here's a few lines of my switch statements:
    PHP Code:
     switch($_GET['tut']){ 
    //3D Studio Max Pages
    case '3d-studio-max-animation'
         
    $lookfor "3DS Max - Animation";
    $title2 "3D Studio Max - Animation";
    include(
    "./includes/tuts.php");
         break; 
    case 
    '3d-studio-max-effects'
         
    $lookfor "3DS Max - Effects";
    $title2 "3D Studio Max - Effects";
    include(
    "./includes/tuts.php");
         break; 
    case 
    '3d-studio-max-lighting'
         
    $lookfor "3DS Max - Lighting";
    $title2 "3D Studio Max - Lighting";
    include(
    "./includes/tuts.php");
         break; 
    case 
    '3d-studio-max-maxscript'
         
    $lookfor "3DS Max - Maxscript";
    $title2 "3D Studio Max - Maxscript";
    include(
    "./includes/tuts.php"); 
    the $lookfor is part of defining what to query from the database and $title2 is for a label above each section when it is displayed...

  5. #5
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anything? anybody?

  6. #6
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Don't really understand what you are looking for...

    Personally, I would use numbers instead of text strings to differentiate among the categories. Plus any title would come from the database instead of being hardcoded in the script.
    Wayne Luke
    ------------


  7. #7
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well basically I'm wondering what Gaheris is talking about in his code he posted...

  8. #8
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would try something like this...
    PHP Code:
    if(isset($_GET['tut'])) {
        
    $hello explode('-'$_GET['tut']);
        
    $lookfor "$hello[0]$hello[2] - $hello[3]";
        
    $study "$hello[0] $hello[1] $hello[2] - $hello[3]";
        include(
    "./includes/tut.php");

    You will need to modify and such, such as inserting php capitalizing functions.

  9. #9
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would you mind explaining what all that means dtang? I'm still pretty new to PHP...

  10. #10
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If tut is passed in GET statement then:
    split tut up into an array using the dashes (-)
    set $lookfor to 'the first word'S 'the second word' - 'the third word'
    set $study to 'the first word' 'the second word' - 'the third word'
    include tuts.php

    Not sure I'd use it - incase you don't always follow that format. But certainly shows how it could be possible.
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •