Jump to content

i need help to convert a script written in ASP to PHP...


fekaduw

Recommended Posts

hello everyone,

last week my boss gave me a web page designed using ASP scripts and asked me to convert it into PHP. i have good knowledge on PHP, but am poor on ASP. hence, i would like someone to help me sort this proble out. here is the code...

<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="includes/dbconnection.inc"-->

<%
     
Dim SQL
Dim oRs,oRS1,oRs2
Dim description
Dim companyinfo
Dim companylist
dim vcompanyid
Dim i,j
Dim Desc
dim vstart
dim vletter

Dim PageNo
Dim Navigation


Dim vcompanyname,vcompanyname1
Dim vcompid
Dim vno
Dim noofcomp
Dim temp1,temp2

Const vPageSize = 15

vstart = request.querystring("start")
vcompanyid = request.querystring("companyid")
PageNo = Request.QueryString("PageNo")

IF PageNo <> "" Then
PageNo = cInt(PageNo)
Else
PageNo = 1
End IF

Set oRS = Server.CreateObject("ADODB.RecordSet")

if vstart="" then
SQL = "SELECT * from tcompany where published = true order by companyname "
else
  SQL = "SELECT * from tcompany where companyname like '"& vstart &"%' and published = true"
end if

oRS.CursorLocation = 3
oRS.Open SQL, oCnn
oRS.PageSize = vPageSize

companylist = ""

i = 1

dim vtotal
dim vinitial
dim vfinal


vtotal = oRs.recordcount

vinitial = (vpagesize * pageno)-vpagesize+1
vfinal = vpagesize * pageno

if vtotal<vfinal then
  vfinal = vtotal
end if

SQL = "SELECT distinct(left(companyname,1)) as name from tcompany where published = true "
set oRs2 = oCnn.execute(sql)

if not oRs2.eof then
  do until oRs2.eof
    vletter = vletter & "<a href=companies.asp?start="& oRs2("name") &">" & oRs2("name") & "</a> "& " | "
  oRs2.movenext
  loop
end if

vletter = vletter & "<a href=companies.asp> All Companies </a>"

IF Not oRS.EOF Then

oRS.AbsolutePage = PageNo
companylist = companylist & "<tr><td colspan='2' height='10' class='brwntxt'>Building Product Producing Companies : "& vtotal &" Companies ( Rec No. "& vinitial &" - " & vfinal & " ) </td></tr>"
    companylist = companylist & "<tr><td colspan='2' height='2' class='brwntxt' align='center'>"& vletter &"</td></tr>"    

    vcompanyname1 = ""
 
Do Until oRS.EOF OR oRs.AbsolutePage <> PageNo
     
  vcompanyname = trim(oRs("companyname"))
 
    'if (vcompanyname=vcompanyname1) then
    '  companylist = companylist & "<tr><td class='brwntxt' width='1'>"& vinitial & ".</td><td align='left'><a href='companies.asp?companyid="& oRS("companyid") &"'><span class='bodylink2'>"& oRS("companyname")&" - " & noofcomp & " Companies" & "</span></a></td><tr>"
  'else
      companylist = companylist & "<tr><td class='brwntxt' width='1'>"& vinitial & ".</td><td align='left'><a href='companies.asp?companyid="& oRS("companyid") &"'><span class='bodylink2'>"& oRS("companyname") &"</span></a></td><tr>"
  ' end if
 
  vcompanyname1 = vcompanyname
 
  i = i+1
      vinitial = vinitial + 1
  oRS.movenext
 
  loop
 
companylist = companylist & "<tr><td colspan='2' height='10'>&nbsp;</td></tr>"

  end if 



 
'Create navigation link
IF (Not oRS.EOF) OR (PageNo > 1) Then
Navigation = ""

For I = 1 to oRS.PageCount
IF I = PageNo Then
Navigation = Navigation & "<a href='companies.asp?PageNo=" & I & "'  style=""font-size:1.5em;"">&nbsp;" & I & "&nbsp</a>"
Else
Navigation = Navigation & "<a href='companies.asp?PageNo=" & I & "'>&nbsp;" & I & "&nbsp</a>"
End IF
Navigation = Navigation & "|"
Next
       
Navigation = Left(Navigation, Len(Navigation) - 1)

IF PageNo > 1 Then
Navigation = "<a href='companies.asp?PageNo=" & (PageNo - 1) & "'>&laquo; Prev</a>&nbsp;" & Navigation
Else
Navigation = "<b>&laquo; Prev</b>&nbsp;" & Navigation
End If

IF Not oRs.EOF Then
Navigation = Navigation & "<a href='companies.asp?PageNo=" & (PageNo + 1) & "'>&nbsp;Next &raquo;</a>"
Else
Navigation = Navigation & "<b>Next &raquo;</b>"
End IF

End IF


if vcompanyid<>"" then

SQL = "SELECT tcompany.companyid as companyid, tcompany.companyname as companyname, tcompany.productno as productno, tcompany.Description as Description, tcompany.logoname as logoname, tcompany.imagename as imagename, tAddress.Organization as Organization, tAddress.Address as Address, tAddress.companyid as companyid1, tAddress.Tel as Tel, tAddress.Fax as Fax, tAddress.Website as Website, tAddress.email1 as email1, tAddress.email2 as email2, tAddress.Pobox as Pobox FROM tcompany INNER JOIN tAddress ON tcompany.companyid = tAddress.companyid where tcompany.companyid=" & vcompanyid
'SQL = "SELECT * from tcompany where companyid=" & vcompanyid
Set oRS1 = oCnn.Execute(SQL)



if not oRS1.eof then
 
  'do until oRS1.eof



companyinfo = companyinfo & "<span class ='brwntxt'>COMPANY INFORMATION </span><br>"
companyinfo = companyinfo & "<br>"

if oRs1("Organization")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1'>" &oRs1("Organization") & "</span>"
end if

if oRs1("Address")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1'>"&  oRs1("Address") & "</span>"
end if


if oRs1("Tel")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1''>"& "Phone : "& oRs1("Tel") &"</span>"
end if

if oRs1("Fax")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1''>"& "Fax : "& oRs1("Fax") &"</span>"
end if

'if oRs1("Website")<>"" then
'  companyinfo = companyinfo &"<span class = 'indent1'>Web Site : <a href='#' onClick=""MM_openBrWindow('" & oRS1("Website") & "','','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=400')"">"&  oRs1("Website") &"</a></span>"
'end if

if oRs1("Website")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1'>Web Site : <a href='companydetail.asp?companyid="& oRs1("companyid") &"'>On Specify Website</a></span>"
end if

if oRs1("email1")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1'>"& "Email: <a href='mailto:"& oRs1("email1") &"'>"& oRs1("email1") &"</a></span>"
end if

if oRs1("email2")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1''>"& "Email 2 : <a href='mailto:"& oRs1("email1") &"'>"& oRs1("email2") &"</a></span>"
end if

if oRs1("Pobox")<>"" then
  companyinfo = companyinfo &"<span class = 'indent1'>"& "P.O.Box : "& oRs1("Pobox") &"</span><br>"
end if




if oRS1("imagename")="" AND oRs1("logoname")="" then
   
description = description & "<tr class='brwntxt'><td colspan='2' valign='top' height='10' align='right'>&nbsp;</td></tr>"
    description = description & "<tr><td valign='top' class='companytitle' colspan='2' align='center'>"& oRS1("companyname")&"</td></tr>"
description = description & "<tr><td colspan='2' align='right'><img src='images/back.jpg' onClick='history.go(-1);'></td></tr>"

desc = companyinfo & "<br>" & oRS1("description")
   
description = description & "<tr><td  valign='top' class='justifiedtext'>"& desc &"</td></tr>"


elseif oRS1("imagename")<>"" AND oRs1("logoname")="" then
   
description = description & "<tr class='brwntxt'><td colspan='2' valign='top' height='10' align='right'>&nbsp;</td></tr>"
    description = description & "<tr><td valign='top' class='companytitle' colspan='2' align='center'>"& oRS1("companyname")&"</td></tr>"
description = description & "<tr><td colspan='2' align='2'><img src='images/back.jpg' onClick='history.go(-1);'></td></tr>"

desc = companyinfo & "<br>" & oRS1("description")

description = description & "<tr><td  valign='top' class='justifiedtext'><span style='float:right'>&nbsp;&nbsp;<img src='admin/upload//"& oRS1("imagename")&"'></span>"& desc &"</td></tr>"


elseif oRS1("imagename")="" AND oRs1("logoname")<>"" then
 
description = description & "<tr class='brwntxt'><td colspan='2' valign='top' height='10' align='right'>&nbsp;</td></tr>"
    description = description & "<tr><td colspan='2' valign='top' align='center'><img src='admin/upload//"& oRS1("logoname")&"'></td></tr>"
description = description & "<tr><td valign='top' class='companytitle' colspan='2' align='center'>"& oRS1("companyname")&"</td></tr>"
description = description & "<tr><td align='right' colspan='2'><a href='#'><img src='images/back.gif' border='0' onClick='history.go(-1);'></a></td></tr>"

desc = companyinfo & "<br>" & oRS1("description")
   
description = description & "<tr><td  valign='top' class='justifiedtext' colspan='2'>"& desc &"</td></tr>"

elseif oRS1("imagename")<>"" AND oRs1("logoname")<>"" then

description = description & "<tr class='brwntxt'><td colspan='2' valign='top' height='10' align='right'>&nbsp;</td></tr>"
    description = description & "<tr><td valign='top' class='companytitle' colspan='2' align='center'>"& oRS1("companyname")&"</td></tr>"
description = description & "<tr><td colspan='2' align='right'><a href='#'><img src='images/back.gif' border='0' onClick='history.go(-1);'></a></td></tr>"
description = description & "<tr><td colspan='2' valign='top' align='center'><img src='admin/upload//"& oRS1("logoname")&"'></td></tr>"

desc = companyinfo & "<br>" & oRS1("description")

description = description & "<tr><td  valign='top' class='justifiedtext' colspan='2'><span style='float:right'>&nbsp;&nbsp;<img src='admin/upload//"& oRS1("imagename")&"'></span>"& desc &"</td></tr>"


end if

else
description = description & "<tr><td  height=''50>&nbsp;</td></tr>"
description = description & "<tr><td  valign='top' class='bodylink2'>No Information found for this company!</td></tr>"
 
end if 
       
End if


%>


any help is really appreciated...
fek.
Link to comment
Share on other sites

Heh...just keep in mind that it basically follows the same logic. Just diferent syntax/code.

[code]<%
Dim thisword
Dim thatword
%>[/code]

Is simply declaring "thisword" "thatword" as variables.

[code]<%
Do Until oRs2.EOF
%>
[/code]
Basically saying keep looping until the record set is empty.

I suppose I can sit here and explain it all but...I would be rewriting all your code for you. I suggest running through some tutorials online and then taking it from there.
Link to comment
Share on other sites

I am familar with VBScript and could help, but to be honest most of the code above is fairly self explanatory. Most of it is just assigning text to the 'description' variable and some IF ELSE statements.

Could you perhaps go through the code and post any questions you have regarding specific code?

Here's a couple of explanations:

[code]<%@ Language=VBScript %>
<%   Option Explicit %>
<!--#include file="includes/dbconnection.inc"-->[/code]
That 1st line is to tell the server what language the code is written in - not needed in PHP
The 2nd line tells the server that the code must explicitly specify variables before they are used. Don't know if there is a similar command in PHP, however it is not needed.
The 3rd line is calling an external file to do the database connection.

[code]vstart = request.querystring("start")[/code]
This would be the same as $vstart = $_GET['start'];

[code]SQL = "SELECT distinct(left(companyname,1)) as name from tcompany where published = true "
  set oRs2 = oCnn.execute(sql)[/code]
This is doing a database query and applying the results to oRs2

[code]if not oRs2.eof then
    do until oRs2.eof
      vletter = vletter & "<a href=companies.asp?start="& oRs2("name") &">" & oRs2("name") & "[/url] "& " | "
    oRs2.movenext
    loop
  end if[/code]
This is a loop to ge through all of the records in the query results. eof = end of record. Similar to:
while ($row = mysql_fetch_assoc($oRs2)) {
 //actions
}
Link to comment
Share on other sites

i understand that most of the codes are self explanatory. but the problem with me is the pieace of code that creates a page. as to my understanding it is gonna display the information in a given page providing a link to the other pages. say 10 records on a given page hidding the others.

i forexample, can not convert this code:

  oRS.CursorLocation = 3
  oRS.Open SQL, oCnn
  oRS.PageSize = vPageSize
 
  companylist = ""
 
  i = 1
 
  vtotal = oRs.recordcount
 
  vinitial = (vpagesize * pageno)-vpagesize+1
  vfinal = vpagesize * pageno
 
  if vtotal<vfinal then
      vfinal = vtotal
  end if
 
  SQL = "SELECT distinct(left(companyname,1)) as name from tcompany where published = true "
  set oRs2 = oCnn.execute(sql)
 
  if not oRs2.eof then
    do until oRs2.eof
      vletter = vletter & "<a href=companies.asp?start="& oRs2("name") &">" & oRs2("name") & "[/url] "& " | "
    oRs2.movenext
    loop
  end if 
 
  vletter = vletter & "<a href=companies.asp> All Companies [/url]"
 
  IF Not oRS.EOF Then
   
      oRS.AbsolutePage = PageNo
      companylist = companylist & "<tr><td colspan='2' height='10' class='brwntxt'>Building Product Producing Companies : "& vtotal &" Companies ( Rec No. "& vinitial &" - " & vfinal & " ) </td></tr>" 
      companylist = companylist & "<tr><td colspan='2' height='2' class='brwntxt' align='center'>"& vletter &"</td></tr>"     
     
i can't find the AbsolutePage, PageSize stuffs in PHP. i tried ASP2PHP converter but it doesn't seem too much helpful. it could be because of some other reason.

but if u know some web links please let me know
Link to comment
Share on other sites

Some of that is specific to retrieving data through an ADO record set. I've never done that in ASP and have no idea how you would do that in PHP. If you know how to connect to an ADO source in PHP, then you just need to lookup those commands in ASP and then use the parallel commands in PHP.

For example:

[code]oRS.CursorLocation = 3
oRS.Open SQL, oCnn
oRS.PageSize = vPageSize[/code]
[b]CursorLocation:[/b] "sets or returns a long value that indicates the location of the cursor service. A cursor is used to: control record navigation, control the visibility of changes in the database, control the updatability of data" http://www.w3schools.com/ado/prop_cursorlocation.asp
The 2nd line appears to be running a query
PageSize: "sets or returns a long value that indicates the maximum number of records allowed on a single page of a Recordset object. Default is 10." http://www.w3schools.com/ado/prop_rs_pagesize.asp

Based upon that I would come to the conclusion that the query is returning records based upon the query starting from location 3 and only grabbing the 1st 10 records.

[code]companylist = ""

  i = 1[/code]
Variable assignments, no explanation needed

[code]vtotal = oRs.recordcount[/code]
Gets the count of records from the query

[code]  vinitial = (vpagesize * pageno)-vpagesize+1
  vfinal = vpagesize * pageno
 
  if vtotal<vfinal then
      vfinal = vtotal
  end if[/code]
More variable assignments

[code]  SQL = "SELECT distinct(left(companyname,1)) as name from tcompany where published = true "
  set oRs2 = oCnn.execute(sql)[/code]
new databse query

[code]  if not oRs2.eof then
    do until oRs2.eof
      vletter = vletter & "<a href=companies.asp?start="& oRs2("name") &">" & oRs2("name") & "[/url] "& " | "
    oRs2.movenext
    loop
  end if [/code]

Similar to
[code]<?php
if (mysql_num_rows($oRs2) > 0 ) {
  while ($row = mysql_fetch_assoc($oRs2)) {
      $vletter = $vletter & "<a href=companies.asp?start=". $row["name"] .">" . $row["name"] . "[/url] " . " | ";
  }
}
?>[/code]

[code]vletter = vletter & "<a href=companies.asp> All Companies [/url]" [/code]
Variable assignment - same as:
[code]$vletter = $vletter . "<a href=companies.asp> All Companies [/url]"; [/code]

[code]      companylist = companylist & "<tr><td colspan='2' height='10' class='brwntxt'>Building Product Producing Companies : "& vtotal &" Companies ( Rec No. "& vinitial &" - " & vfinal & " ) </td></tr>" 
      companylist = companylist & "<tr><td colspan='2' height='2' class='brwntxt' align='center'>"& vletter &"</td></tr>" [/code]
More vairable assignments.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.