我在MySql表page_order
中有一個單元格。當我使用php表單添加一個新行時,沒有任何內容寫入這個單元格。 我已經使用jQuery sortable
與數據庫中的記錄,當我們移動的項目,然後這個單元格page_order
更新。排序不正確?
這裏是我的代碼部分
<?php
include 'dbs.php';
$db = new DB();
$users = $db->getRows('artists',array('order_by'=>'page_order ASC'));
if(!empty($users)): $count = 0; foreach($users as $user): $count++;
?>
<?php $idd = $_GET['id']; ?>
<?php if(($user['interline'] == NULL) && $user['event_id'] == $idd){ ?>
<div class="action-box" id="<?php echo $user['id']; ?>">
<div class="action-box-count">
<div class="count-number"><?php echo $count; ?></div>
<div class="count-time">
<div class="count-time-top">15:37 <span>21</span></div>
<div class="count-time-bottom">15:50 <span>29</span></div>
</div>
</div>
<div class="action-box-info">
<p class="user-name"><?php echo $user['fullname']; ?></p>
<p class="user-info"><?php echo $user['artist1']; ?></p>
<p class="user-info"><?php echo $user['artist2']; ?></p>
</div>
</div>
<?php } ?>
<?php if(($user['interline'] != NULL) && $user['event_id'] == $idd){ ?>
<div class="action-box action-end" id="<?php echo $user['id']; ?>">
<div class="action-box-count">
<div class="count-number"><?php echo $count; ?></div>
</div>
<div class="action-box-info">
<div class="text-center"><?php echo $user['interline']; ?></div>
</div>
</div>
<?php } ?>
<?php endforeach; else: ?>
<tr><td colspan="5">Not found......</td></tr>
<?php endif; ?>
<a href="javascript:void(0);" id="addLink" onclick="javascript:$('#openForm').toggle();"><div class="action-box action-add"></div></a>
<?php
$idint = $_GET[id];
echo "<a class='action-box action-add-small' href=\"interline.php?idi=".$idint."\"><div class='text-center'><span class='icon'>Interline</span></div> </a>";
?>
<input type="hidden" name="page_order_list" id="page_order_list" />
</div>
</div>
然後我使用AJAX來發送文件的請求時,我處理:
for($i=0; $i<count($_POST["page_id_array"]); $i++)
{
$query = "
UPDATE artists
SET page_order = '".$i."'
WHERE id = '".$_POST["page_id_array"][$i]."'";
mysqli_query($connect, $query);
}
阿賈克斯
$(document).ready(function(){
$("#order_list").sortable({
placeholder : "ui-state-highlight",
update : function(event, ui)
{
var page_id_array = new Array();
$('#order_list div').each(function(){
page_id_array.push($(this).attr("id"));
});
$.ajax({
url:"order.php",
method:"POST",
data:{page_id_array:page_id_array},
success:function(data)
{
alert(data);
}
});
}
});
});
的問題是: 1.錯誤的寫入db的步驟,即不是1,2,3,4,5,但如下所示:10,22,27,30,33 2.第二個問題是,當我檢查<?php if(($user['interline'] != NULL)
輸出另一個字符串 - 排序和數字行爲通常是可怕的。
請告訴我如何弄清楚?
小更新: 隨着: '如果(($用戶[ '隔行'] == NULL)&& $用戶[ 'EVENT_ID'] == $ IDD){} 如果(($用戶[」從一開始,幾乎所有東西都是好的(從5開始,遠到6,7,8,9,...)。 。),但排序是混亂 隨着: '如果(($用戶[ '隔行'] == NULL)&& $用戶[ 'EVENT_ID'] == $ IDD){}' 用的步驟混亂(10,12,17,27,30,...),但排序是正確的 –
沒有ajax調用,很難猜到發生了什麼 –
另外,兩個'if'語句中div的數量似乎沒有加起來,這可能是導致排序問題 –