3 different variables in PHP = 3 Pages??

Discussion in 'PHP' started by vaniaul, Feb 26, 2008.

  1. #1
    Hello All,

    Would like to greet everyone as its my first post in the PHP section:

    I have just purchased an old domain. It has the following URLs:

    1. www.abc.com/view_products.php?id=stools
    2. www.abc.com/view_products.php?id=chairs
    3. www.abc.com/view_products.php?id=cushion

    - Is there a way that I can use all these 3 URLs on 3 different pages?
    - Can I create 3 separate pages for each of these URLs?

    All your help and knowledge is greatly appreciated!

    You can even point me to some knowledge-base, and I can educate myself!

    Cheers!
     
    vaniaul, Feb 26, 2008 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes and no... The three URLs point to the same file on the server : view_products.php with 3 different parameters.
    It depends on how the script was written, but I guess that only some parts of the page will change like products descriptions/meta tags...
     
    selling vcc, Feb 26, 2008 IP
  3. DomainCo.US

    DomainCo.US Well-Known Member

    Messages:
    2,124
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    100
    #3
    It can be done, basically view_products will act as your controller and redirects it to a different view depending on the parameter.
     
    DomainCo.US, Feb 26, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    A quick mockup of viewproducts.php"

    
    <?php
    if($id=="stool")
    {
    echo "Things to do if id is equal to stool";
    
    }
    elseif($id=="cushion")
    {
    echo "Things to do if id is equal to cushion";
    
    }
    ?>
    
    PHP:
    That way all your pages are contained in 1 file.
     
    blueparukia, Feb 26, 2008 IP
  5. vaniaul

    vaniaul Peon

    Messages:
    144
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh wow... U explained it all! I got it... Thanks a Lot!

    Have a Great Day :)
     
    vaniaul, Feb 26, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    I'd use switch, in this case.
     
    nico_swd, Feb 26, 2008 IP
  7. vaniaul

    vaniaul Peon

    Messages:
    144
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    nico_swd,

    Can u pls explain me the advantage of using switch. Thanks in advance!
     
    vaniaul, Feb 26, 2008 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    It's faster than multiple if/elseif statements. It's also a bit cleaner, IMO.
     
    nico_swd, Feb 26, 2008 IP
  9. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #9
    I never notice speed differences betweenif/else and switch/case, but yeah, it's cleaner. Though if you're a messy coder I bet you can make it messy.
     
    blueparukia, Feb 26, 2008 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    Well the speed difference is very minimal. And if you're using only a few if/elseif then it won't matter too much. But if you're using a lot, you should use switch() instead.
     
    nico_swd, Feb 26, 2008 IP
  11. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The difference being that the condition is only evaluated once and then compared multiple times in a switch as opposed to one evaluation/comparison for each if and elseif. If/elseif statements are more versatile, but switches are designed to be more efficient in this special case.
     
    The Critic, Feb 26, 2008 IP