dongzhang1839 2012-06-24 10:56
浏览 24
已采纳

年份的唯一ID

Im looking for how to generate a unique id that will remain unique for one year. I use uniqid() function but I've heard that there is a chance for duplicates, so I do this: $id = rand(0,1000) . uniqid();

Will this remain unique for a whole year?

  • 写回答

1条回答 默认 最新

  • duanbinmi8970 2012-06-24 12:04
    关注

    The only way to be sure you have a unique Id in your data set is to test for it.

    $id = uniqid(2012); //returns a 13 character string plus it will append 2012 for 17 characters.
    $resultSet = //get dataSet from somewhere
    
    foreach($resultSet as $row) {
        if ($row['id'] = $id) {
        //do some stuff
       }
    }
    

    This is a simple example of how you might flow this in a simple application. I'm sure there is probably a way to do this SQL as well (but I don't know SQL that well).

    Alternatively you could just let the database start at 1 and assign each record a unique value for it's ID.

    You failed to mention your purpose so these suggestions are a best guess.

    Good Luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程