Solved

Question For lozloz ONLY

Posted on 2003-12-01
5
226 Views
Last Modified: 2006-11-17
Hi again loz!

I have a script written in ASP that I use to display multiple pages of content with only one page....


http://www.mysite.com/index.asp?pg=home
http://www.mysite.com/index.asp?pg=terms

Here is the script I use:  <%ASP%>
<%
                                          action=Request.querystring("action")
      if action = "" then
                action = "home"
      end if

      Select Case action

                                                Case "home"
                                                      Server.Execute"content/home.asp"
                                                Case "services"
                                                      Server.Execute"content/home.asp"
                                                     Case "payments"
                                                      Server.Execute"content/home.asp"
                                                      Case "faq"
                                                      Server.Execute"content/home.asp"            
                        
Case else
End Select
%>

As I'm just beginning to learn PHP (and mind you it hasn't been as easy as I thought it would be) could you please give me a PHP example for converting this code?

Also, one other question I have is this....I reference all of my links by calling the value of the page I'm on (i.e., <a href="<%Request.ServerVariables("SCRIPT_NAME")%>?action=payments">).  The page the Request.ServerVariables will call is the index page.  Can you also give an example of that in PHP?

I hate to be soo much trouble, but I was very pleased with your help in my previous question.

Thanks in advance,

Trent
0
Comment
Question by:wkpreferredsolutions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
hi there,

interesting what you say about php - i learnt php first and have found learning asp a lot harder than php.. maybe it's the 2nd language in the sequence which is harder. this should be quite easy to follow logically:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home"
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case: "services"
    include("content/home.asp");
    break;
  case: "payments"
    include("content/home.asp");
    break;
  case: "faq"
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

seems a bit strange wanting to include the same page for each action though so i assume you'll be changing this later

Request.ServerVariables in asp is equivalent to $_SERVER["SCRIPT_NAME"] but generally we use $_SERVER["PHP_SELF"] as this is a string containing the filename relative to the server's root

so for an example for your link - <?php print <a href=\"" . $_SERVER["PHP_SELF"] . "?action=payments\">Payments</a>"; ?>, or to be exact in the form of your code:

<a href="<? print $_SERVER["PHP_SELF"]; ?>"?action=payments">Payments</a>

good luck

loz
0
 

Author Comment

by:wkpreferredsolutions
Comment Utility
Thanks for the quick reply loz!

I was always told that ASP was one of the harder languages to learn and PHP would be so much easier to learn after learning ASP!!!  I think I was lied to, :-)

The same include file was from a quick cut and paste in a script I was working on that I never finished.

I'm getting a parse error whenever the script reaches this line:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home" <=========================Parse Error On This Line

Trent
0
 
LVL 13

Accepted Solution

by:
lozloz earned 500 total points
Comment Utility
sorry that's me being silly, all the cases should be in the following form:

case "home":

so:

switch ($action){ // Select Case action
  case "home" :
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case "services":
    include("content/home.asp");
    break;
  case "payments":
    include("content/home.asp");
    break;
  case "faq":
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

cheers,

loz
0
 

Author Comment

by:wkpreferredsolutions
Comment Utility
Yep!  That fixed it!

Thanks again for the great answers!  Points are on the way!

Trent
0
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
glad to help

loz
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now