私はいくつかのチュートリアルに取り組んでいます。私はかなり長い間見回してきましたが、頭に釘を打つことはできません。これまでの私のコードは次のとおりです。
索引
<?php
$result = mysql_query("SELECT MAX(listid) AS listid FROM testtable");
while($row = mysql_fetch_array($result))
{
for ($i=1; $i<=(int)$row['listid']; $i++) {?>
<div class="heading" >List <?php echo $i; ?></div>
<ul class="connectedSortable sortable">
<?php
$item = "SELECT * FROM testtable WHERE listid='".$i."' ORDER BY posid ASC";
$list = mysql_query($item); $x = 1;
while($row2 = mysql_fetch_array($list, MYSQL_ASSOC)){
?>
<li class="ui-state-default" id="recordsArray_<?php echo $row2['linkid']; ?>">
<?php echo $row2['linkname']; ?></li>
<?php $x++;
}
?>
</ul>
<?php
}}
?>
Javascript
$(document).ready(function(){
$(function () {
$(".sortable").sortable({
connectWith: ".connectedSortable",
distance: 5,
zIndex: 0,
opacity: 0.6,
cursor: 'move',
update: function() {
var order = $(this).sortable("serialize")
+ '&action=updateRecordsListings';
$.post("updateDB.php", order)}
}).disableSelection();
});
});
および updateDB.php コード
<?php
require("connect2.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
$posidCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
$query = "UPDATE testtable SET posid = ".$posidCounter."
WHERE linkid=".$recordIDValue;
mysql_query($query) or die('Error, insert query failed');
$posidCounter = $posidCounter + 1;
}
}
?>
今、すべてがうまくいくようです。しかし、私が達成しようとしているのは、リスト項目を接続されたリストに移動し、データベースを更新してその項目の位置を新しいリストに反映させることです。現時点では、元のリスト内の位置を更新しているだけです。
私はこれらすべてに非常に慣れていないので、どんな助けも素晴らしいでしょう! 前もって感謝します。
私のテーブルは次のようになります。
+----------+----------+---------+--------+
| linkname | linkid | posid | listid |
+----------+----------+---------+--------+
| 1 | 1 | 2 | 1 |
| 1 | 2 | 1 | 1 |
| 1 | 3 | 1 | 2 |
| 1 | 4 | 2 | 2 |
+----------+----------+---------+--------+