Re: [請益] 選擇性限制條件

看板PHP作者 (寶貝豬)時間16年前 (2009/09/19 20:17), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
以下是我的方式, 僅供參考. 若ok則歡迎使用. 以bit為'屬性值'的單位, 所以利用一個整數值可以儲存多屬性. <?php //帳號註冊 define('USER_REGISTER',1); //Email認證 define('USER_EMAIL',2); //手機認證 define('USER_MOBILE',4); //身份認證 define('USER_IDCARD',8); //增強版身份認證 define('USER_IDCARDEXT',16); //職業認證 define('USER_CAREER',32); class certification{ //設定屬性: public function set_attr($user_id,$attr){ $a=$attr; if(is_array($attr)){ foreach($attr as $v){ $a=($a | $v); } } $link=dblink(); $sql=sprintf(" update users set certification=(certification | %d) where id=%d ",$a,$user_id); mysql_query($sql,$link); } //反設定屬性: public function unset_attr($user_id,$attr){ $a=$attr; if(is_array($attr)){ foreach($attr as $v){ $a=($a & $v); } } $link=dblink(); $sql=sprintf(" update users set certification=(certification & ~%d) where id=%d ",$a,$user_id); mysql_query($sql,$link); } //檢查屬性是否已設定? public function isset_attr($user_id,$attr){ $link=dblink(); $sql=sprintf(" select * from users where id=%d ",$user_id); $rs=mysql_query($sql,$link); $r=mysql_fetch_assoc($rs); if(!is_numeric($attr)) $attr=constant($attr); if( $attr == ($r['certification'] & $attr) ) return true; return false; } }//class ?> ※ 引述《j87b0003 (山貓好威)》之銘言: : 在網路上買賣東西,賣方可以選擇性設定買方條件, : 例:0.不限制 : 1.通過手機認證 : 2.通過e-mail驗證 : 3.好友名單內 : 4.拒絕黑名單..等 : ps:僅需符合一項買方就可向該賣方購買 : 在db部份,目前是想到用一欄位標示該選擇的條件, : 如:1,2,4 、0 、2,4 等等 : 在php部份,則是抓出上述欄位寫出對應之程式碼, : 再丟回db做過濾條件。 : 不知道有沒有更好的方法或建議, : 不管是在db部份或php部份。 : 謝謝大家指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.186.77 ※ 編輯: bobju 來自: 59.104.186.77 (09/19 20:20)

09/19 21:33, , 1F
大概有個初步方向了,感謝你的建議
09/19 21:33, 1F
文章代碼(AID): #1AjClj_H (PHP)
討論串 (同標題文章)
文章代碼(AID): #1AjClj_H (PHP)