我有三個數據庫表。使用拖放表發送和刪除記錄到數據庫
-Paid
-Partially付費
-Owes
當有人爲我送自己的user_id,姓名等,以帳戶註冊我的「欠」數據庫表,然後輸出他們的名字進入我在'Owes'列中有一個拖放表。到目前爲止,如果我將任何人的姓名移動到任何其他類別(付費/部分付費),我不知道如何從Owes數據庫中刪除該記錄,並將名稱插入到新的數據庫表中,以便更改是永久性的。
真正讓我失望的是如何用拖放表來做到這一點。我不知道如何應用這樣的邏輯,即當某些東西被放入該列時,過去的記錄被刪除,並且新的東西被添加到該特定的表中,或者如何在沒有提交按鈕或頁面重新加載的情況下進行更改。
什麼是我可以做到這一點的方式,以及我如何構造它?
PHP
<?php
//Payment Section
$con = mysqli_connect("localhost", "root", "", "db");
$paid_run = mysqli_query($con,"SELECT * FROM paid ORDER BY id DESC");
$partially_paid_run = mysqli_query($con,"SELECT * FROM partial_payment ORDER BY id DESC");
$owes_run = mysqli_query($con,"SELECT * FROM owes ORDER BY id DESC");
$paid_numrows = mysqli_num_rows($paid_run);
$partially_paid_numrows = mysqli_num_rows($partially_paid_run);
$owes_numrows = mysqli_num_rows($owes_run);
if($paid_numrows > 0){
while($row = mysqli_fetch_assoc($paid_run)){
$paid_id = $row['user_id'];
$paid_name = $row['name'];
}
}
if($partially_paid_numrows > 0){
while($row = mysqli_fetch_assoc($partially_paid_run)){
$partially_paid_id = $row['user_id'];
$partially_paid_name = $row['name'];
$partially_paid_amount = $row['payment'];
}
}
if($owes_numrows > 0){
while($row = mysqli_fetch_assoc($owes_run)){
$owes_id = $row['user_id'];
$owes_name = $row['name'];
}
}
?>
$(function() {
$("#paid, #partially_paid, #owes").sortable({
connectWith: ".tdPayment",
remove: function(e, ui) {
var $this = $(this);
var childs = $this.find('div');
if (childs.length === 0) {
$this.text("Nothing");
}
},
receive: function(e, ui) {
$(this).contents().filter(function() {
return this.nodeType == 3; //Node.TEXT_NODE
}).remove();
},
}).disableSelection();
});
表
<table class="paymentTable" id="dragTable">
<tr>
<th class="thPayment">Paid</th>
<th class="thPayment">Partially Paid</th>
<th class="thPayment">Owes</th>
</tr>
<tr>
<td class="tdPayment" id="paid">
<div>
<?php
if ($paid_name == true) {
echo $paid_name;
} else {
echo "No one has paid";
}
?>
</div>
</td>
<td class="tdPayment" id="partially_paid">
<div>
<?php
if ($partially_paid__name == true) {
echo $partially_paid__name . " - " . $partially_paid_amount;
} else {
echo "No one has made a partial payment";
}
?>
</div>
</td>
<td class="tdPayment" id="owes">
<div>
<?php
if ($owes_name == true) {
echo $owes_name;
} else {
echo "Everyone has paid something";
}
?>
</div>
</td>
</tr>
</table>
我已經完成了第1步,第2步我可以非常輕鬆地完成。我只是不知道如何將我所做的操作與拖放表集成到更新db中。我不確定如果我將某個人的姓名從Owes轉到Paid列,腳本如何識別名稱進入該列,以及該列如何表示我真正想要它代表的內容。 – Becky
謝謝你真的給我一個好的開始。這有助於一堆。我有一個問題,但。當名稱將通過while循環從我的數據庫中輸出時,我該如何幫助數據用戶ID。我可以有一天5個名字,然後5個人可以註冊,然後我有10個。這些名稱不會是靜態代碼。 – Becky
您將必須使用PHP生成HTML代碼。爲用戶查詢數據庫,然後遍歷結果並執行類似'echo'