2010-03-28 4 views
-1

나는 초보 프로그래머이며 내가 가지고있는 유일한 경험은 고전 ASP에 있다는 것을 인정할 것이다. 이 ASP 코드를 PHP로 변환하는 방법을 찾고 있습니다. 리눅스 박스에만 액세스 할 수 있지만 나를위한 학습 도구로 사용할 수있는 고객을위한 것입니다.이 코드를 ASP에서 PHP로 변환하면

레코드 및 기능 :

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 

표시 페이지/루프 : 도움에 미리

감사

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 
+2

지금까지 무엇이 있습니까? 어떻게 작동하지 않니? –

답변

1

그것은 다음과 같이 보일 것 ...

$sqldate = strftime('Y-m-d',time()); // time defaults to now - change unix time to string 
$sql = "SELECT * FROM tblXYZ WHERE element_8 = 2 AND element_9 '$date'"; 

$pdoCon = new PDO($connString, $username, $password); 

$outputTpl = '<div><td width="200" valign="top" align="center"><a href="%s" style="text-decoration: none;"><div id="ad_header">%s</div><div id="store_name" valign="bottom">" %s</div><img id="photo-small-img" src="http://xyz.com/files/%s" /><br /><div id="ad_details">%s</div></a></td></div>'; 

$count = 0; 
foreach($pdoCon->query($sql) as $row) { 
    $counter++; 
    echo sprintf(
     $outputTpl, 
     $row['element_6'], 
     $row['element_3'], 
     $row['element_5'], 
     'http://xyz.com/files/' . $row['element_7'], 
     $row['element_4'] 
); 

    if($counter == 3) { 
    echo '<tr></tr>'; 
    $counter = 0; 
    } 
} 
+0

고마워요. 제가 찾고있는 것이 맞습니다. 불행히도 내게 500 내부 서버 오류를주는. – jethomas

+0

Im 당신은 MSSQL (실험적으로 생각하는 것) 또는 아마도 PDO에 대한 PDO dirver가 없다고 추측 할 것입니다. 내가 MSSQl을 사용하지 않고 아무 생각도하지 않는다면 거기에 당신 만의 Yore가 있습니다. 이것은 주로 텍스트의 루핑과 출력을 비교할 수있는 일반적인 예였습니다. 특정 DB 측면에 대해서도 연구해야합니다. PHP에서 MSSQL 연결에 대한 새로운 질문을 게시하는 것이 좋습니다. 그럼 거기서가. – prodigitalson

+0

감사! 나는 그것을 들여다 볼 것이다! – jethomas

관련 문제