表items
檢查用戶是否投票支持的最大項目數,他可以投票
id maxVotes parent type
10 2 9 heading
11 0 10 item
12 0 10 item
表votes
userId votedFor parent
1 11 10
1 12 10
2 12 10
我想檢查是否有物品存在,如果用戶已經投票支持該標題下允許的最大數量的項目。
在上面的示例中,表items
包含項目。表votes
包含用戶投的票。
表items
type : heading
指定用戶可投票的最大件數col : maxVotes
。在這種情況下,它是2
。
在表votes
user 1
已投票的2個項目,並可以投票沒有更多的items
是在該標題下。用戶2可以投1個項目。
它就這樣下去。
就我目前做的(使用PHP),就是:
select id, parent from items where id = 11 //The item exists.
select maxVotes from items where id = parent // This gives me the maximum items a user can vote for.
select count(votedFor) as votes from votes where userId = 1 // This'll give me 2.
User 1 can vote no more, but user 2 can vote once more -> Add his vote to the votes table
你能想到的更容易,效率更高除了我上面這樣做之外,採用複雜的方法來做到這一點?
我可以對事物進行修改,因爲這還沒有實現。或者,這是最好的方法嗎?
諾曼你發佈的問題後逃脫? :) –
我在這裏。在檢查網站之前,你不能告訴有人回覆。該網站不會立即向您發送每封回覆的電子郵件;-) – Norman
從現在開始,您已經發布了32秒。我很快就回復你了。但你40分鐘後回覆。不要責怪這個網站。如果發佈任何答案或評論的意思。在您的收件箱(stackoverflow收件箱)中,您將收到通知。你不知道嗎? –