Solved

Question For lozloz ONLY

Posted on 2003-12-01
5
232 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 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

707 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