0

我一直在尝试编写一个阅读列表,您可以在其中添加您喜欢的文章,然后单击顶部的小 x 将它们从列表中删除。我使用 JQuery .click 从数据库中删除故事,将其从列表中删除。但是,当我尝试一次删除多个故事时,它只会删除最后一个点击的故事。我不知道它可能是什么。我认为这可能与全局变量和局部变量有关,但我不知道从哪里开始。

这是一些 HTML,一个类似于我删除的 div:

<li id="arrayorder_146">
<div class="reading_list drop-shadow lifted">
<div class="reading_list_container">
<a class="deletefromrl" data-storyid="146" data-parent="arrayorder_146">x</a>
<p class="reading_list_story">
<a class="rlstory" href="" data-storyid="146">iSteal: Apple Products Cause NYC Crime Wave
</a></p></div></div></li>

这是 JQuery 函数:

    $(document).ready(function(){ $(function() {
        $('a.deletefromrl').click(function(){
            $(this).closest('li').fadeOut('slow');
            var order = $('#list ul').sortable("serialize") + '&update=update' + '&id=' + $(this).attr('data-storyid'); 
            $.post("deletefromReadingList.php", order, function(theResponse){
                    $("#response").html(theResponse);
                }); 

这是 php deletefromReadingList:

    <?php 
 require_once('compress.php');
  require_once('startsession.php');
 require_once('admin_start_session.php');
 require_once('db_connect_variables.php');
 require_once('input_variables.php');

 $array = $_POST['arrayorder'];
 $id = $_POST['id'];

if ($_POST['update'] == "update")
 {
$user_id = $_SESSION['user_id'];
$admin_id = $_SESSION['admin_id'];

$listorder = '';
$i=0;

foreach ($array as $idval) 
{
    if(($idval == $id) && ($i == 0))
    {
        $i++;
        continue;
    }
    $listorder = $listorder . $idval . ',';
}

$listorder = substr_replace($listorder ,"",-1);

if(!empty($user_id) && empty($admin_id))
{
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
        $query = "UPDATE reading_list SET listorder = " . $listorder . " WHERE user_id = " . $user_id;
        mysql_query($query) or die('Error, insert query failed');
        echo 'Saved until 9AM Tomorrow';
}
else if(empty($user_id) && !empty($admin_id))
{
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
        $query = "UPDATE reading_list SET listorder = '" . $listorder . "' WHERE admin_id = " . $admin_id;
        mysqli_query($dbc, $query) or die('Error, insert query failed');
        echo 'Saved until 9AM Tomorrow';
}
else
{
    $_SESSION['readinglist'] = $listorder;
    setcookie('readinglist', $listorder, mktime(6, 59, 59, date('m'), (date('d')+1), date('y')));    // expires at midnight
    echo 'Saved until 9AM Tomorrow';
}
  }

  ?>
4

0 回答 0