2016-03-23 20 views
1

jqueryとajaxを使用してドラッグ&ドロップソート可能なテーブルを作成しています。PHPクエリインループでデータベースを更新していません

私の問題は、時間の約10%しか働かないということです。

ここに私のjsコードです。ここで

<script type="text/javascript"> 
// When the document is ready set up our sortable with it's inherant function(s) 
$(document).ready(function() { 
    $("#test-list").sortable({ 
     handle : '.handle', 
     update : function() { 
      var order = $('#test-list').sortable('serialize'); 
      $("#info").load("tow_sort2.php?"+order); 
     } 
    }); 
}); 
</script> 

はtow_sort2.phpページです:ここで

<?php 
include("../_includes/db_connection.php"); 

/** 
* This is where you would inject your sql into the database 
* but we're just going to format it and send it back 
*/ 
$array =array(); 
foreach ($_GET['listItem'] as $position => $item) 
{ 
    $sql = "UPDATE tow SET tow_order = '$position' WHERE tow_id = '$item'"; 
    $conn->query($sql); 
    $array[] = $sql; 
} 
print_r($array); 
?> 

が印刷されている配列です。

Array ([0] => UPDATE tow SET tow_order = '0' WHERE tow_id = '5924' [1] => UPDATE tow SET tow_order = '1' WHERE tow_id = '5925' [2] => UPDATE tow SET tow_order = '2' WHERE tow_id = '5922' [3] => UPDATE tow SET tow_order = '3' WHERE tow_id = '5923') 

Screenshot of the Table

+0

問題が解決しない場合は、エラーメッセージが表示されますか? –

+0

データベースプロバイダとは何ですか?トランザクションはどのように管理されますか? – soyuka

+0

目的とする動作は何ですか?どのくらい正確に動作していないのですか? – BPS

答えて

0

私はこの問題はあなたのことだと思いますexecの代わりにメソッドクエリを使用しています:

$conn->exec($sql); 

ちなみに、あなたのコードはSQLインジェクションに対して脆弱です。代わりにprepared文を使用するか、変数を確認してください。

関連する問題