mysql比较不起作用

时间:2014-05-06 04:48:51

标签: php mysql mysqli

我在表中有两列名为delete1delete2,其中包含删除邮件的用户的名称。我在表中有5行如下(第一列是空cos,用户已撤消已删除的消息)

id   delete1   delete2   message_id
1              Danny     1
2              Danny     1
3              Danny     1
4                        1
5                        1

登录用户现在是Danny,以下查询正在更新所有delete1列,它不应该这样做,因为delete2与Danny相同。有谁知道我在这做什么?

$ms_id = 1;
$username = 'Danny'; 

$stmt = $db->prepare("select * from thread where delete1 != ? and delete2 != ?");
echo $db->error;
$stmt->bind_param('ss',  $username, $username);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();

//this query is updating all delete1 even though delete2 has to be different from Danny, I was hoping only to update the last 2 rows.
if($row['delete1'] == '' && $row['message_id'] == $ms_id && $row['delete2'] != $username){
    $trd = $db->prepare('update `thread` set `delete1` = ? where `message_id` = ?');
    echo $db->error;
    $trd->bind_param('si', $username, $ms_id);
    $trd->execute();
    }

    else{
    if($row['delete2'] == '' && $row['message_id'] == $ms_id && $row['delete1'] != $username){
    $trd = $db>prepare('update `thread` set `delete2` = ? where `message_id` = ?');
    echo $db->error;
    $trd->bind_param('si', $username, $ms_id);
    $trd->execute();

    }

0 个答案:

没有答案