Converting this code from ASP to PHP
Posted
by jethomas
on Stack Overflow
See other posts from Stack Overflow
or by jethomas
Published on 2010-03-28T15:35:34Z
Indexed on
2010/03/28
15:43 UTC
Read the original article
Hit count: 206
I'll admit I'm a novice programmer and really the only experience I have is in classic ASP. I'm looking for a way to convert this asp code to PHP. For a customer who only has access to a linux box but also as a learning tool for me.
Thanks in advance for the help:
Recordset and Function:
Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
else
pd = n
end if
End Function
'declare the variables
Dim Connection
Dim Recordset
Dim SQL
Dim SQLDate
SQLDate = Year(Date)& "-" & pd(Month(Date()),2)& "-" & pd(Day(Date()),2)
'declare the SQL statement that will query the database
SQL = "SELECT * FROM tblXYZ WHERE element_8 = 2 AND element_9 > '" & SQLDate &"'"
'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'open the connection to the database
Connection.Open "PROVIDER=MSDASQL;DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;UID=xxxxx;PWD=xxxxx;database=xxxxx;Option=3;"
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
Display page/loop:
Dim counter
counter = 0
While Not Recordset.EOF
counter = counter + 1
response.write("<div><td width='200' valign='top' align='center'><a href='" & Recordset("element_6") & "' style='text-decoration: none;'><div id='ad_header'>" & Recordset("element_3") & "</div><div id='store_name' valign='bottom'>" & Recordset("element_5") & "</div><img id='photo-small-img' src='http://xyz.com/files/" & Recordset("element_7") & "' /><br /><div id='ad_details'>"& Recordset("element_4") & "</div></a></td></div>")
Recordset.MoveNext
If counter = 3 Then
Response.Write("</tr><tr>")
counter = 0
End If
Wend
© Stack Overflow or respective owner