會有人請幫助我,我有一個塊用戶腳本。基本上一切正常。插入mysql表結果兩次以獲得多列中的重複結果?
當用戶單擊其他用戶配置文件中的塊時,會回顯用戶標識,並將user_id和其他profile_id插入到數據庫中,並將列'已阻止'從'0'設置爲'1'。
登錄的用戶現在不能看到他們被阻止的其他用戶,但他們阻止的其他用戶仍然可以看到他們的個人資料。
我的數據庫的工作方式是,它需要兩套ID兩列像這樣:
user_id | blocked_id | blocked
1 2 1
2 1 1
爲了讓兩個用戶不看對方,都被阻擋我需要嘗試插入兩個身份證幾乎兩次。
這有點像重複插入到表中的值來創建兩次相同的結果,但只能在表格列中反過來。
所以此刻我有:
$sql = mysql_query("INSERT INTO ptb_block_user (user_id, blocked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")");
,我會需要兩次插入這些值,但輪相反的方式,所以它看起來像上面的表格。
我希望即時通訊讓自己清楚,有誰知道我該怎麼做?
謝謝。
<?php
session_start();
confirm_logged_in();
if (isset ($_GET['to'])) {
$user_to_id = $_GET['to'];
}
if (!isset($_GET['to']))
exit('No user specified.');
$user_id = $_GET['to'];
$sql = mysql_query("INSERT INTO ptb_block_user (user_id, blocked_id) VALUES (".$_SESSION['user_id'].", ".$user_to_id.")");
$result1 = mysql_query("UPDATE ptb_block_user SET blocked='1' WHERE user_id=".$_SESSION['user_id']."")
or die(mysql_error());
if($result1)
{
$_SESSION['message2']="<div class=\"infobox-profile\"><strong>User Blocked</strong> - This user has successfully been blocked. You will no longer be abler to interact with each other's profiles.</div><div class=\"infobox-close\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
else
if($result2)
{
$_SESSION['message2']="<div class=\"infobox-favourites\"><strong>User Unblocked</strong> - This user has successfully been unblocked. You can now interact with each other's profiles.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>
是的,這是幾乎完成它,你給我的代碼確實重複的值,所以兩個id都在他們的現在,但只有一組值是更新到'1',另一個停留在'0 「?我能做些什麼來解決這個問題? –
只需將'blocked'添加到'INSERT'。更新回答 –