SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I want to set up a database so I can use a set page ie display.php or template.php or something so that if i type the address display.php?123 or template.php?789 the server could cross refrence a database and then *** some code to the page in an ssi fashion so the server would add something like <font face="x" size="2">Hello some text would be here</font> in to a TD of the page. Can you help??

    Many Many Many Thanks in Advance
    Rick

    RBoycey

  2. #2
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Setup a switch statement in your "included" file. Pass a variable to it before you include it so it knows which switch statement to read. Then all you have to do is edit different switch statements to do different things. You can even call the switch statements at different times in your main file be recalling the include file and passing it the switch variable you want.

    If you don't know how to do a switch statement, or you want further help, just let me know and I'll post an example. I would right now, but I'm on my way out the door.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Hotdog, Thankz for the reply - as I am new to databasing I have someidea of the switch's you mentioned but no idea of how to implement them or thier code etc.
    Please could you post or even better email me a reply - rboycey@freezone.co.uk

    Many Thanks
    Rick

    rboycey@freezone.co.uk
    RBoycey

  4. #4
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A switch statement is nothing more than a fancy if/then statement. First, let's go over how a switch statement works.

    You first setup your code stating that you are using a switch statement by doing the following:
    Code:
    <?php
        switch($variable) {
    
        }
    ?>
    The $variable can be any name you want to give to the switch statement and will be used as the variable to define which switch case you will be using.

    Now you are wondering what a switch case is. Well, in a regular if/then statement, you go through a series of logical steps...

    Code:
    if something is true
        then do this
    if 1 wasn't true
        then do this
    if 1 and 2 weren't true
        then do this
    if everything is not true to this point
        then do this
    In a switch statement, instead of using this logical series to step through what you want to do, you setup cases. You then tell the switch statement which case you want to use. For example, let's say you want to make a desert with fruit. The desert is your switch statement name and the fruit are the switch cases.

    If you are making a strawberry pie, you would say:

    Code:
    $pie = "strawberry";
    
    switch($pie) {
        case "strawbery" :
    
            One cup strawberrys;
            One cup sugar;
            etc....;
    
        break;
    
        case "apple" :
    
            One cup apples;
            Two cups sugar;
            etc....;
    
        break;
    }
    Take a look at the above example. You'll see how I passed the variable $pie the name strawberry. This will look for the switch statement named pie and then load the class named strawberry. The class strawberry then has the recipe for how to make a strawberry pie. If I would have said $pie = "apple";, then it would have loaded the switch statement pie and the class apple with the recipe for an apple pie.

    Take a look at how the classes are set up. You use the form:

    Code:
    class "class name" :
    
        your php code;
    
    break;
    Now in your case, I would setup a switch statement in an include file. The way you would then setup and call the included switch file is as follows:

    PHP Code:
    $myVariable "something";
    include(
    "switchFile.inc"); 
    Then in your included switch file you would have this:

    Code:
    <?php
        switch($myVariable) {
            
            case "something" :
                My php code here;
            break;
    
            case "something" :
                My php code for a different function here;
            break;
        }
    ?>
    And there you have it. A nice way of writing different code for different situations. You could even pass the switch variable in the url when calling your main php file. In the page b4, just put the switch variable name in the URL and assign a variable to it.

    Code:
    <a href="main.php?myVariable=something">click here</a>
    Then when main.php is opened, it has $myVariable already set. All you then need to do is include your file with the switch statement.

    Hope this helps.
    Last edited by HotDog; Mar 6, 2001 at 16:54.
    Joe Eliason
    Just a dog learnin' PHP from cat.


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
  •