2010-06-11 7 views
1

ASP.NET (VB.NET)에서 다음 PHP를 작성하는 방법을 아는 사람이 있습니까?PHP 스크립트를 ASP.NET으로 변환

foreach ($_GET['listItem'] as $position => $item) : 
    $sql[] = "UPDATE `table` SET `position` = $position WHERE `id` = $item"; 
endforeach; 

$ _GET의 데이터는 [ '되는 listItem는']는 다음과 같습니다

항목을 [] = 1 개 & 항목을 [] = 2 & 항목은 [] =

+0

PHP에 대해 알지 못해서 의도를 설명해 주시면 더 도움이 될 수 있습니까? 감사. –

답변

1

3 내가 조금 알고 PHP하지만 나는 $ 위치가 0 기반 인덱스라고 가정합니다. 그렇지 않은 경우에는 위치 변수를 선언하는 두 줄의 코드를 서로 바꿔야합니다. 코멘트는 '문자로 시작됩니다. 난 당신이 VB.net 말했다 통지를하지 않았기 때문에


'Request.Params accesses parameters from form posts, query string, etc. 
Dim pairs = Request.Params("listItem").Split("&") 

For i As Integer = 0 To pairs.Length - 1 

    Dim token = pairs(i) 
    Dim position = i.ToString() 
    'string position = (i + 1).ToString(); 
    Dim id = Convert.ToInt32(token.Split("=")(1)) 
    Dim sql = "UPDATE table SET position = " + position + " WHERE [id] = " + id.ToString() 
    'This line does the same thing, a bit more eloquently and efficiently 
    'Dim sql = String.Format("UPDATE table SET position = {0} WHERE [id] = {1}", position, id.ToString()) 

Next 

은 내가 먼저 C#으로 이런 짓을. 여기 C# 버전이 있습니다. 내가 그것을 남겨 둘 수있을 것 같았습니다. C#의 미묘한 차이를 명확하게 보여주기 위해이 말을 약간 말했습니다.

// Request.Params accesses parameters from form posts, query string, etc. 
string[] pairs = Request.Params["listItem"].Split('&'); 
for (int i = 0; i < pairs.Length; i++) 
{ 
    string token = pairs[i]; 
    string position = i.ToString(); 
    // string position = (i + 1).ToString(); 
    int id = Convert.ToInt32(token.Split('=')[1]); 
    string sql = "UPDATE table SET position = " + position + " WHERE [id] = " + id; 
    // This line does the same thing, a bit more eloquently and efficiently 
    //string sql = String.Format("UPDATE table SET position = {0} WHERE [id] = {1}", position, id.ToString()); 
} 
관련 문제