做一个抽奖活动,设计表:
奖品表option:
oid   奖品ID
name  奖品名兑换码表code:
oid  奖品ID
code  兑换码
status 是否使用 0:未使用 1:已使用现在要求可以加入重复兑换码,而且兑换码通过文本框换行得到
编辑奖品和奖品兑换时如何处理code表的status呢,如果有相同的code,就不能直接update code set status=1 where code='{$code}'了。

解决方案 »

  1.   

    如果 $code 是多行的兑换码
    那么可以
    $code = join(',', preg_split("/[\r\n]+/", $code));
    处理成以逗号分隔的兑换码串
    使用时
    where code in ($code)
    即可
      

  2.   


    有重复的怎么处理,比如现在有个人获奖了,兑换码是11,但是数据库中有两个11,怎么更新status
      

  3.   

    为什么要允许有重复的呢?
    真有重复也可以
    select oid from  code where code='yourcode' and status=0 limit 1
    如果有结果oid,那么更新就是
    update code set status=1 where oid='oid'