0

update.phpスクリプトの前に if ステートメントを挿入するにはどうすればよいですか?
if ステートメントは、リスト内の jquery ドロップ項目がそのリスト Mysql データベースにあるかどうかを確認し、そうでない場合はリスト/テーブル データベースに挿入し、update.php


update.phpを実行します。

require("db.php");

$action                 = mysql_real_escape_string($_POST['action']); 
$updateRecordsArray     = $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {

///////currently stuck//////////
    if (???ID not present in lists database???){
    $sql = "INSERT INTO records1 SELECT * FROM records WHERE ID = (???missing array element ID???)
///////////////////////////////

        $query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE ID = " . $IDValue;
        mysql_query($query) or die('Error, insert query failed');
        $listingCounter = $listingCounter + 1;  
}else{
       $query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
        mysql_query($query) or die('Error, insert query failed');
        $listingCounter = $listingCounter + 1;  
    }

if ステートメントは $updateRecordsArray を参照し、配列内のすべての ID がリスト MySQL テーブルに存在することを確認する必要があります。アイテムがない場合は、更新を挿入して実行し、そうでない場合は更新を実行します。

変更されていない update.php

 require("db.php");

$action                 = mysql_real_escape_string($_POST['action']); 
$updateRecordsArray     = $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {

    $query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
    mysql_query($query) or die('Error, insert query failed');
    $listingCounter = $listingCounter + 1;  
}

echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}

Javascript:

    $(function() {
    $("#contentLeft ul").sortable({opacity: 0.6, cursor: 'move', update: function() {
        var order = $(this).sortable("serialize") + '&action=updateRecordsListings'; 
        $.post("updateDB.php", order, function(theResponse){
            $("#contentRight").html(theResponse);
        });                                                              
    }                                 
    });
});

HTML:

    <div id="contentleft">
    <ul></UL>
    </div>

        <div id="contentRight">
      <p>Array will be displayed here.</p>
      <p>&nbsp; </p>
    </div>
4

2 に答える 2

0
if (!SELECT 1 from records WHERE ID = $IDValue)

records上記の行は、レコードがテーブルで利用可能かどうかを示します。この条件が満たされた場合、レコードを挿入できます。

于 2013-09-11T05:21:53.223 に答える