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!
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...
It can be done, basically view_products will act as your controller and redirects it to a different view depending on the parameter.
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.
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.
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.
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.