2015-01-27 3 views
0

어제 나는이 오류를 만났습니다. 나는이 오류를 만났습니다. 아래의 코드는 재귀적인 MariaDB 테이블에서 두 개의 포스트가 전환되도록되어 있습니다.PDO 업데이트 쿼리가 전혀 작동하지 않습니다

$cid은 장소를 위 또는 아래로 전환해야하는 게시물의 ID입니다. $pid은 상위 ID입니다. $ord은 게시물이 부모 아래에있는 장소입니다. $dir은 게시물을 위, 아래로 이동할 방향을 나타냅니다.

첫 번째 게시물이 이동해야하는 위치의 게시물은 첫 번째 게시물의 첫 번째 위치를 차지합니다.

<?php 

    $cid = isset($_GET['cid']) ? $_GET['cid'] : ""; 
    $pid = isset($_GET['pid']) ? $_GET['pid'] : ""; 
    $ord = isset($_GET['ord']) ? $_GET['ord'] : ""; 
    $dir = isset($_GET['dir']) ? $_GET['dir'] : ""; 

    if($cid == "" || $pid == "" || $ord == "" || $dir == "") die('nu gick det åt pipsvängen...'); 

    if($dir == "up") { 
     $opos = $ord--; 
    } elseif($dir == "down") { 
     $opos = $ord++; 
    } else { 
     die('ingen riktning'); 
    }; 

    $ostmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :onp WHERE foralder = :pid AND ordning = :oop"); 
    $ostmt -> bindValue(":onp", $ord); 
    $ostmt -> bindValue(":pid", $pid); 
    $ostmt -> bindValue(":oop", $opos); 

    $ostmt -> execute(); 

    $cstmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :cnp WHERE id = :cid"); 
    $cstmt -> bindValue(":cnp", $opos); 
    $cstmt -> bindValue(":cid", $cid); 

    $cstmt -> execute(); 

?> 

이것은 전혀 적용되지 않습니다. 나는 테이블에서 아무 것도 바꿀 수 없으며 어떤 오류도 없다.

+0

당신의 모든 값을 반향하고 괜찮아요 확인 :

여기에 최종 해결책은? 그렇지 않으면 오류가 다른 곳에서 업데이트 될 수 있습니다. –

+1

연결이 어디 있습니까? – Mihai

+0

@Rakesh : 예, 모든 변수를 확인했습니다. 그들의 가치는 내가 기대하는 것입니다. –

답변

0

그래서 오늘은 마지막으로 그것을했다! 나는 모든 것을 잘못보고 있었다. 어쩌면 내가 그것을 언급하지 않았다는 사실을 제외하고는 스크립트에 결함이 없습니다. 오늘 나는 모든 것을 주석하기 시작했고 나의 변수를 더 나은 이름으로 바꿨다. 나는 잘못 생각했다. 업데이트 쿼리가 작동했지만 잘못된 라인을 업데이트 했으므로 아무 일도 없었습니다.

<?php 

    $absid = isset($_GET['cid']) ? $_GET['cid'] : ""; // ID of absolute row 
    $parid = isset($_GET['pid']) ? $_GET['pid'] : ""; // Absolute row's parent ID 
    $abspos = isset($_GET['ord']) ? $_GET['ord'] : ""; // Current position of absolute row 
    $newrelpos = $abspos;        // New position of relative row 
    $dir = isset($_GET['dir']) ? $_GET['dir'] : "";  // Direction to move absolute row 

    if($absid == "" || $parid == "" || $abspos == "" || $dir == "") die('missing variable(s)'); 

    // Generate absolute row's new position 
    if($dir == "up") { 
     $newabspos = $abspos - 1; 
    } elseif($dir == "down") { 
     $newabspos = $abspos + 1; 
    } else { 
     die('direction not set'); 
    }; 

    $relpos = $newabspos; // Current position of relative row 

    // Fetch relative row's ID 
    $stmt = $dbh -> prepare("SELECT id FROM csa_categories WHERE foralder = :parid AND ordning = :pos"); 
    $stmt -> bindValue(":parid", $parid); 
    $stmt -> bindValue(":pos", $relpos); 
    $stmt -> execute(); 
    $row = $stmt -> fetch(); 

    $relid = $row['id']; // Relative row's ID 

    // Update absolute row 
    $astmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :newabspos WHERE id = :absid"); 
    $astmt -> bindValue(":newabspos", $newabspos); 
    $astmt -> bindValue(":absid", $absid); 
    $astmt -> execute(); 

    // Update relative row 
    $rstmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :newrelpos WHERE id = :relid"); 
    $rstmt -> bindValue(":newrelpos", $newrelpos); 
    $rstmt -> bindValue(":relid", $relid); 
    $rstmt -> execute(); 

?> 
0

이러한 방법 중 하나를 사용해 보셨습니까?

$ostmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :onp WHERE foralder = :pid AND ordning = :oop"); 
$ostmt -> bindParam(":onp", $ord); 
$ostmt -> bindParam(":pid", $pid); 
$ostmt -> bindParam(":oop", $opos); 
$ostmt -> execute(); 

또는

또한
$ostmt = $dbh -> prepare("UPDATE csa_categories SET ordning = :onp WHERE foralder = :pid AND ordning = :oop"); 
$ostmt -> execute(array(':onp'=>$ord,':'pid'=>$pid,':oop'=>$opos)); 

,이 문은 출력을 생성 않습니다

$ostmt = $dbh -> prepare("SELECT ordning FROM csa_categories WHERE foralder = :pid AND ordning = :oop"); 
$ostmt -> bindParam(":pid", $pid); 
$ostmt -> bindParam(":oop", $opos); 
$ostmt -> execute(); 
+0

나는 행운없이 처음 두 제안을 시도했다. 세 번째 쿼리는 예상대로 한 행을 반환합니다. –

+0

그리고'print_r ($ dbh-> errorInfo());'가 비어 있다고 확신합니까? – Astronout

+0

Array ([0] => 00000 [1] => [2] =>)'를 반환하므로 문제가 없습니다. –

관련 문제