SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    main.php?page=blah

    Hello all sorry for the topic name its just that I don't know what is the name of that. What they call it. Anyways let mme get to my real problem.

    I got this script in a table in my main.php file:

    ---
    <?
    if ($page == home) {
    $title="{Home}";
    include ("inc/index.inc");
    }
    elseif ($page == about) {
    $title="{About}";
    include ("inc/about.inc");
    }
    else {
    $title="{Home}";
    include ("inc/index.inc");
    }
    ?>
    --

    Now what i'm trying to do is use this same method for a page that is effected by this in the main.php file.
    Lets say the /inc/index.inc file. Can I put the same script in it? Will it work or will I need to use another method.

    Thanks You

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could have the same thing in the include file, if that is what you are asking

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also you should consider using a switch for things like this:
    PHP Code:
    <?php

    switch ($page) {
        case 
    'about':
            
    $title="{About}";
            include (
    "inc/about.inc");
            break;
        case 
    'home':
        default:
            
    $title="{Home}";
            include (
    "inc/index.inc");
            break;
    }

    ?>
    It looks much better and makes it easier to read the code as well.

    [Switch]

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what do u mean fly?

    What do you mean fly that the switch is better to use?

  5. #5
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, Switch is better to use. It's more efficient and looks much cleaner. It's easier to read, pass variables too.

    Think of it as a massive if statement, without all the if statements.

    I love it - I don't know how I ever lived without it
    Chrispian H. Burks
    Nothing To Say

  6. #6
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, utilizing the if-elseif-else construct is more efficient than utilizing the switch-case-break method. And which one looks "prettier" is a matter of opinion.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Thanks you all

    Thanks for your help all of you

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's see some stats then people!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Opinion sminion

    Switch Case Break, Switch Case Break, Switch Case Break.

    I said it three times first. It must be so

    Kidding of course. My experince with Switch has been that everyone who has shown me how to code always did it that way, and most of the programs I download that do any kind of menu system (load=whatever) always used Switch.

    I think it's preferred more over the if-then-else to make it more readable and managable and the logic seems more clear - but that's just my opinion I use if-then-else all the time, just not for the load=action situation.
    Chrispian H. Burks
    Nothing To Say

  10. #10
    Apache Expert i_like_php's Avatar
    Join Date
    Nov 2001
    Location
    Dallas, Texas
    Posts
    1,342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down

    the only way i could achieve this effect was by using an mysql database.
    i love php

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we see your code then? We might be able to help

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •