Forum Moderators: open

Message Too Old, No Replies

ASP equivalent of PHP code

         

PumpkinHead

2:18 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Hi,

I may have to convert a php site to ASP. I have always used php to include certain pages into my main index page.

E.g

<?
if ($page=="") {include("nav/navigation_index.php");
};
if ($page=="home") include("nav/navigation_index.php");
};
if ($page=="page1") include("nav/nav_page1.php");
};
?>

The links would then have index.php?page=home or index.php?page=page1 etc

Could someone tell me how to do this using ASP or point me the right direction as for now I do not need to learn a great deal.

Thanks in advance, to anyone who is able to help.

too much information

2:46 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%
page_name = Request.querystring("page")

if (page_name = "home") then
Response.write "<!--#include file='nav/navigation_index.asp'-->"
elseif (page_name = "page1") then
Response.write "<!--#include file='nav/nav_page1.asp'-->"
else
Response.write "<!--#include file='nav/navigation_index.asp'-->"
end if
%>

I'm currently switching to PHP from ASP so I feel your pain. Just remember that insided of your double quotes you should use single quotes so that you don't accidently end your statement.

mattglet

6:20 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry TMI, it doesn't work that way ;)

In order to include a page with ASP, yes you have to use:
<!--#include file="nav/navigation_index.asp"-->

The catch is that the #include directive is a server-side call, and it's processed before any ASP code. So that means you cannot use an IF...END IF statement to choose whether or not to use it.

Here's an idea of how ASP code is processed by the server/browser:
1st - Server Side Includes
2nd - ASP
3rd - HTML (processed by browser)

A little more info here [w3schools.com].

defanjos

6:34 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See this post [webmasterworld.com] - message 3.
I never tried it, so not sure if it works or not.

defanjos

6:58 pm on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried the code on the message above, and it seems to work.
Here is an example:

<%
dim something
if page_name = "home" then
something = "1"
elseif page_name = "page1" then
something = "2"
end if

Select Case Something
Case 1
Server.Execute "nav/navigation_index.php"
Case 2
Server.Execute "nav/nav_page1.php"
Case Else
Server.Execute "nav/navigation_index.php"
End Select

%>

PumpkinHead

4:31 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Thanks again all :)