ydeewana
asked on
how to convert asp to php
HI, i have few pages created in asp, and i just found out that my webserver is not supporting asp (post method) they told me to use PHP. but i am still learning and i need to finish by end of this week. below code i need to tranfer in to PHP. can someone help me out please. Thanks.
ASP code
========================== ========== =======
<head>
<title>Pictures</title>
</head>
<body bgcolor="#786854" text="#FFFFB9">
<%
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adUseClient = 3
Const adCmdText = 1
Dim conn, rs, connString, qString
set conn=Server.CreateObject(" ADODB.Conn ection")
set oRs=Server.CreateObject("A DODB.recor dset")
conn.Provider="Microsoft.J et.OLEDB.4 .0"
connString=Server.MapPath( "imagetest .mdb")
conn.Open connString
%>
Pictures Page
<%
Dim mypage, numpages, numrecs, pagesize
mypage = CInt( Request("page") )
If mypage=0 Then mypage=1
pagesize = CInt( Request("recs") )
If pagesize = 0 Then pagesize = 10 ' If we aren't given a value use 10
Set rs = Server.CreateObject("ADODB .RecordSet ")
rs.PageSize = pagesize
rs.CacheSize = pagesize
rs.CursorLocation = adUseClient
qString = "SELECT * FROM Table1"
rs.Open qString, conn, adOpenForwardOnly, adLockReadOnly, adCmdText
numpages = rs.PageCount
numrecs = rs.RecordCount
If mypage > numpages Then mypage = numpages
If mypage < 1 Then mypage = 1
rs.AbsolutePage = mypage
Response.Write("<P> <B>" & numrecs & " records found.</B>" )
Response.Write("<BR> Page " & mypage & " of " & numpages & "</P>")
Response.Write("<CENTER>")
Dim i
For i=1 To pagesize
If NOT rs.EOF Then
'Response.Write(rs("Name") & " | " & rs("Data") & " <BR>")
'
response.Write "<tr><a href='http://home.1asphost.com/Yash/images/" & rs("Images") & "'> <img src=images/" & rs("Images") & " border=5 celspacing=5 width=175 height=175></a></tr>"
rs.MoveNext
End If
Next
Response.Write("<P>")
Dim x, lb, ub
For x=1 To numpages
lb = (x-1) * pagesize + 1
ub = x * pagesize
If ub > numrecs Then ub = numrecs
If x <> mypage Then
Response.Write("<A HREF=pictures.asp?page=" & x & "&recs=" & pagesize & ">" & lb & "-" & ub & "</A>")
Else
Response.Write(lb & "-" & ub)
End If
If x <> numpages Then Response.Write(" | ")
Next
Response.Write("</CENTER>" )
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
%>
</body>
</html>
ASP code
==========================
<head>
<title>Pictures</title>
</head>
<body bgcolor="#786854" text="#FFFFB9">
<%
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adUseClient = 3
Const adCmdText = 1
Dim conn, rs, connString, qString
set conn=Server.CreateObject("
set oRs=Server.CreateObject("A
conn.Provider="Microsoft.J
connString=Server.MapPath(
conn.Open connString
%>
Pictures Page
<%
Dim mypage, numpages, numrecs, pagesize
mypage = CInt( Request("page") )
If mypage=0 Then mypage=1
pagesize = CInt( Request("recs") )
If pagesize = 0 Then pagesize = 10 ' If we aren't given a value use 10
Set rs = Server.CreateObject("ADODB
rs.PageSize = pagesize
rs.CacheSize = pagesize
rs.CursorLocation = adUseClient
qString = "SELECT * FROM Table1"
rs.Open qString, conn, adOpenForwardOnly, adLockReadOnly, adCmdText
numpages = rs.PageCount
numrecs = rs.RecordCount
If mypage > numpages Then mypage = numpages
If mypage < 1 Then mypage = 1
rs.AbsolutePage = mypage
Response.Write("<P> <B>" & numrecs & " records found.</B>" )
Response.Write("<BR> Page " & mypage & " of " & numpages & "</P>")
Response.Write("<CENTER>")
Dim i
For i=1 To pagesize
If NOT rs.EOF Then
'Response.Write(rs("Name")
'
response.Write "<tr><a href='http://home.1asphost.com/Yash/images/" & rs("Images") & "'> <img src=images/" & rs("Images") & " border=5 celspacing=5 width=175 height=175></a></tr>"
rs.MoveNext
End If
Next
Response.Write("<P>")
Dim x, lb, ub
For x=1 To numpages
lb = (x-1) * pagesize + 1
ub = x * pagesize
If ub > numrecs Then ub = numrecs
If x <> mypage Then
Response.Write("<A HREF=pictures.asp?page=" & x & "&recs=" & pagesize & ">" & lb & "-" & ub & "</A>")
Else
Response.Write(lb & "-" & ub)
End If
If x <> numpages Then Response.Write(" | ")
Next
Response.Write("</CENTER>"
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
%>
</body>
</html>
ASKER
CirTap,
First of all Thanks for the information. I know that points are very low for this questions. I did not expect anyone to convert my code from ASP to PHP. There are few reasons i put my code there. one was when i put it, i did not know how that works. Second, when i search online, i found there are few converter which will allow you to convert code from ASP to PHP. Therefore i thought they someone might have done it.
anyway, Thanks again for providing me good information.
First of all Thanks for the information. I know that points are very low for this questions. I did not expect anyone to convert my code from ASP to PHP. There are few reasons i put my code there. one was when i put it, i did not know how that works. Second, when i search online, i found there are few converter which will allow you to convert code from ASP to PHP. Therefore i thought they someone might have done it.
anyway, Thanks again for providing me good information.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: Scrit {http:#8744235}
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
snoyes_jw
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: Scrit {http:#8744235}
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
snoyes_jw
EE Cleanup Volunteer
you don't really expect *anyone* will convert this code into PHP for "20 points", do you? :-)
ASP and PHP practically have nothing in common, so any 'convertion' of a ASP script will be a complete re-write of that very script -- with a few exceptions like the SELECT statement in the one you posted ;-)
There are some "ASP emulators" for PHP, but according to "them, telling you to use PHP", none is installed on their system.
1.) Your script is using a database, which requires a total different approach *and* a different database engine in a typical LAMP system.
I assume "they" are running a Linux box (the 'L' in LAMP), so may have access to a MySQL (resposible for the 'M') or PostgreSQL database server -- if at all --, and you should check this first.
Both DBs mentioned require different PHP code unless using a generic db-layer, and a proper 'mirror' of the DB tables you currently have in that Access file.
The PHP code to handle the database request also differs from the ADODB*) object model in ASP.
In general you can't simply use an Access MDB file on a linux box and you *should not* use one on a production server either.
2.) Your script appears to be some sort of an "Image/Picture Gallery". Instead of converting this one just go ahead an download one of the billion galleries available for PHP. Some of them require a database, some don't.
Get a simple one to start with, then get familiar with PHP and it's principles of databases connections, and then make "your script" as sophisticated as you want.
Btw: if you're familiar JavaScript you'll find out that PHP has much more in common with JS than VBscript/ASP.
Unfortunately I can't provide you with any link to a certain gallery-script because I always coded them by myself with respect to a site's specific layout etc.
Here are some links you can search for "gallery"
- http://www.phpfreaks.com/
http://www.phpfreaks.com/scripts/Image_Galleries/6.php
- http://php.resourceindex.com/
- http://www.hotscripts.com/PHP/
- http://px.sklar.com/search.html
They were all listed at http://www.php.net/links.php
And of course: go and get the PHP manual from http://www.php.net/download-docs.php (available in many languages)
If you are running Windows I recommend the 'CHM/Windows Help' format as it allows a full text search.
Have fun
CirTap
*) there's an object oriented database abstraction layer for PHP (nice term<g>) called ADODB as well, providing similar functionality as and is AFAIK "inspired" by the "original" ADODB.