SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    cd /pub; more beer diacono's Avatar
    Join Date
    Dec 2000
    Location
    Horsham, West Sussex, UK
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i just started having fun with php and did something like this:
    Code:
    switch($id);
    {
      case 3:
        include ("3.inc");
        break;
      case 2:
        include ("2.inc");
        break;
      case 1:
        include ("1.inc");
        break;
      default:
        include("default.inc");
    }
    and i then use urls like index.html?id=1, index.html?id=2, etc.
    but if i use index.html on its own i get the results from 2.inc and not default.inc ?? why?

    if i use index.html?id=5000 i get default.inc but not when i use index.html on it own... what am i doing wrong?
    tia
    DIEGO MOORE

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Weird ! I must admit that not needing to declare variables before use still freaks me out a bit. I know you can get away with it in VB (because of the variant type) and PHP (loose typing) - but maybe its not reliable?

    Also, as it is dangerous not to initialise variables in C++, I guess I have developed the "conservative" habbit of always doing so in my coding.

    So I would write your code like this:
    Code:
    if ( ! $id ) 
    {
       $id = -1;
    }
    
    switch($id);
    {
      case 3:
        include ("3.inc");
        break;
      case 2:
        include ("2.inc");
        break;
      case 1:
        include ("1.inc");
        break;
      default:
        include("default.inc");
    }
    Give that a go and see if corrects the problem.

    PS. You web site looks great - very impressive. I was just looking at your case prototype. Are you planning to live in it when its built? Its huge!
    Last edited by freakysid; Mar 3, 2001 at 05:02.

  3. #3
    cd /pub; more beer diacono's Avatar
    Join Date
    Dec 2000
    Location
    Horsham, West Sussex, UK
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats the cool thing about php. the variables dont ahve to be assigned... a lot easier than C or C++

    anyway the whole thing works ok EXCEPT when i use index.html (ie, no varible)
    DIEGO MOORE

  4. #4
    SitePoint Enthusiast djrs's Avatar
    Join Date
    Feb 2001
    Location
    Canada
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you naming the file with the php code in it "index.html" if you are the reason it's not working is becuase it has to be index.php.
    http://www.hostinquiry.com
    Look up your host today!
    ----------------------------
    ~Dylan Schiedel

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that would totally account for it, seeing as how part of the file is working for him - so whether he was mistaken on the file name, or if he's setup to parse .html files for PHP code, it's obvoiusly working a bit.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am pretty sure the major problem or at least one major problem is the existence of a semicolon at the end of the swtich line
    PHP Code:
    switch($id);

    should be

    PHP Code:
    switch($id)

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    cd /pub; more beer diacono's Avatar
    Join Date
    Dec 2000
    Location
    Horsham, West Sussex, UK
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the file has a php extension (otherwise the rest wouldnt work )

    i'll try what freddydoesophp said...
    thanx
    DIEGO MOORE

  8. #8
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually... it would work if you changed your MIME types to have *.html files parsed by the php engine....
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  9. #9
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't be the problem, since some of the other code was processing, so either the .html files are already being parsed that way, or he mis-typed and he meant to type ".php" - either way, I think Freddy found the bug.


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
  •