-1

以前に尋ねて解決した質問から構築しています:フロントエンドmysql、行の削除

基本的に、ユーザーが DB を表示できるフロント エンドがあります。各行の横に削除ボタンを配置する代わりに、複数の行を選択できるチェックボックスが必要です。次に、ユーザーが 1 つの削除ボタンをクリックするだけで、選択したすべての行が削除されます。php と mysql をまったく知らないので、既に持っているコードにどのようにアプローチすればよいかわかりません。

現在、onclick は削除関数を呼び出します。誰でも助けることができますか?

mysql データの html を長いストロングに出力する php ファイルがあります。変更が必要な部分は次のとおりです。

$display_string .= "<td class='blank'><input type=\"button\" VALUE=\"Delete\" onclick='delFunction(" . $row['ID'] . ")' ></td>";

次に私の削除機能:

function delFunction(ID){
    // confirm delete
    if (!confirm(\"Are you sure you want to delete?\")) return false;

    var ajaxRequest;  // The variable that makes Ajax possible!


    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");
            } catch (e){
                // Something went wrong
                alert(\"Your browser broke!\");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('ajaxDiv');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }

    var queryString = \"?ID=\" + ID


    ajaxRequest.open(\"GET\", \"delete_row.php\" + queryString, true);
    ajaxRequest.send(null); 
}
4

1 に答える 1

0

To my understanding of your problem, I am posting some codes for both front and back ends

Front-End Sample Code

<body>
<form action="delete.php" method="post">
<input type="checkbox" name="del_chk[]">Item1
<input type="checkbox" name="del_chk[]">Item2
<input type="checkbox" name="del_chk[]">Item3
<input type="checkbox" name="del_chk[]">Item4
.
.
<input type="submit">
</form>

................

Your back-end code would now be...

<?php
if(isset($_POST['del_chk'])){
$chkbox=$_POST['del_chk'];
foreach($chkbox as $key=>$value) {

//Now you can get your value and use it in mysql delete statements


//for example
$del_query="DELETE FROM `yourtable` WHERE `pri_key`=$value;";
if(mysql_query($del_query)) {
echo "Successful Deletion of: ".$value;
}
else 
{
echo "Unsuccessful Deletion of: ".$value;
} 

} //end foreach
}
?>

I don't know much of ajax. but you can use ajax to call this page..

于 2012-06-20T02:04:11.997 に答える