?
Solved

Question For lozloz ONLY

Posted on 2003-12-01
5
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9855269
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
ID: 9855694
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 2000 total points
ID: 9855729
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
ID: 9855734
Yep!  That fixed it!

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

Trent
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9855837
glad to help

loz
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

777 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