Re: [請益] PHP 寫加入好友
※ 引述《olivet (smallred)》之銘言:
推
05/04 00:12,
05/04 00:12
→
05/04 00:13,
05/04 00:13
→
05/04 00:28,
05/04 00:28
只要增設一個欄位嘛@@?
就一般的 case 大概是另外建一個 Table 來存
以下以 php + mysql 當作範例
tableUser tableFriend
id, userName id, ownerId, friendId, type
tableUser.id 就當作流水號,也直接是使用者的 userId
tableUser.userName 使用者的帳號
tableFriend.id 好友的流水號,可以當作主鍵或唯一鍵
來做新增修改刪除的依據
(當然也可以用ownerId與friendId來識別,不過這是我的習慣)
talbeFriend.ownerId 就是欲加入別人為好友的人的 Id
talbeFriend.friendId 就是被加入的人的 Id
tableFriend.type 友誼的類別,好友、壞人,只有好友的話也可以不要這欄
// 查詢是否有此帳號
$sql = "SELECT `id` FROM `tableUser` WHERE `userName`='{$_POST['name']}'";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1)
{
$friendId = mysql_fetch_array($result);
$friendId = $friendId[0];
$sql = "INSERT INTO `tableFriend`
(`ownerId`, `friendId`, `type`)
VALUES ('{$_SESSION['id']}', '{$friendId}', '{$type}');";
if ($result != mysql_query($sql))
{
// 新增錯誤
}
}
還有一些前置的 sql injection 要自己過濾
如果 mysql 函式有錯要通知我 ///// 我是憑著自己的記憶在打
因為常常用到,所以都用自己包的物件來做DB處理了…
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.145.202.66
→
05/04 01:15, , 1F
05/04 01:15, 1F
推
05/04 17:34, , 2F
05/04 17:34, 2F
→
05/04 19:08, , 3F
05/04 19:08, 3F
推
05/05 15:57, , 4F
05/05 15:57, 4F
以補上流水號的意義
※ 編輯: chrisQQ 來自: 203.145.202.66 (05/05 18:24)
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章