久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='RcVeH'><style id='RcVeH'><dir id='RcVeH'><q id='RcVeH'></q></dir></style></legend>
      <bdo id='RcVeH'></bdo><ul id='RcVeH'></ul>

      <i id='RcVeH'><tr id='RcVeH'><dt id='RcVeH'><q id='RcVeH'><span id='RcVeH'><b id='RcVeH'><form id='RcVeH'><ins id='RcVeH'></ins><ul id='RcVeH'></ul><sub id='RcVeH'></sub></form><legend id='RcVeH'></legend><bdo id='RcVeH'><pre id='RcVeH'><center id='RcVeH'></center></pre></bdo></b><th id='RcVeH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RcVeH'><tfoot id='RcVeH'></tfoot><dl id='RcVeH'><fieldset id='RcVeH'></fieldset></dl></div>
      <tfoot id='RcVeH'></tfoot>
    1. <small id='RcVeH'></small><noframes id='RcVeH'>

      1. 如何在laravel中為每個用戶生成唯一的隨機值并將

        How to generate unique random value for each user in laravel and add it to database(如何在laravel中為每個用戶生成唯一的隨機值并將其添加到數(shù)據(jù)庫中)

                <bdo id='zdxXY'></bdo><ul id='zdxXY'></ul>

              • <tfoot id='zdxXY'></tfoot>

                <small id='zdxXY'></small><noframes id='zdxXY'>

                  <tbody id='zdxXY'></tbody>
              • <i id='zdxXY'><tr id='zdxXY'><dt id='zdxXY'><q id='zdxXY'><span id='zdxXY'><b id='zdxXY'><form id='zdxXY'><ins id='zdxXY'></ins><ul id='zdxXY'></ul><sub id='zdxXY'></sub></form><legend id='zdxXY'></legend><bdo id='zdxXY'><pre id='zdxXY'><center id='zdxXY'></center></pre></bdo></b><th id='zdxXY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zdxXY'><tfoot id='zdxXY'></tfoot><dl id='zdxXY'><fieldset id='zdxXY'></fieldset></dl></div>
                <legend id='zdxXY'><style id='zdxXY'><dir id='zdxXY'><q id='zdxXY'></q></dir></style></legend>
                  本文介紹了如何在laravel中為每個用戶生成唯一的隨機值并將其添加到數(shù)據(jù)庫中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在開發(fā)一個活動組織網(wǎng)站.在這里,當用戶注冊活動時,他將獲得一個唯一的隨機數(shù)(10 位),我們用它來生成條形碼并將其郵寄給他.現(xiàn)在,

                  I am developing a event organization website. Here when the user registers for an event he will be given a unique random number(10 digit), which we use to generate a barcode and mail it to him. Now,

                  1. 我想為每個注冊的活動設(shè)置唯一的編號.
                  2. 也是隨機的

                  一種解決方案是獲取數(shù)組中的所有隨機數(shù)并使用 Php rand(1000000000, 9999999999) 生成一個隨機數(shù),然后循環(huán)并檢查所有值.獲取不等于數(shù)組中任何值的第一個值并將其添加到數(shù)據(jù)庫中.

                  One solution is to grab all the random numbers in an array and generate a random number using Php rand(1000000000, 9999999999) and loop through and check all the values. Grab the first value that doesn't equal to any of the values in the array and add it to the database.

                  但我認為可能有更好的解決方案.有什么建議嗎?

                  But I am thinking that there might be a better solution to this. Any suggestion?

                  推薦答案

                  您的邏輯在技術(shù)上沒有問題.但是,如果您的應用程序吸引了大量用戶,那么在資源和計算時間方面,獲取所有隨機數(shù)可能會變得不必要地昂貴.

                  Your logic isn't technically faulty. However, if your application attracts lots of users, fetching all of the random numbers may well become unnecessarily expensive, in terms of resources and computation time.

                  我建議另一種方法,即生成一個隨機數(shù),然后根據(jù)數(shù)據(jù)庫進行檢查.

                  I would suggest another approach, where you generate a random number and then check it against the database.

                  function generateBarcodeNumber() {
                      $number = mt_rand(1000000000, 9999999999); // better than rand()
                  
                      // call the same function if the barcode exists already
                      if (barcodeNumberExists($number)) {
                          return generateBarcodeNumber();
                      }
                  
                      // otherwise, it's valid and can be used
                      return $number;
                  }
                  
                  function barcodeNumberExists($number) {
                      // query the database and return a boolean
                      // for instance, it might look like this in Laravel
                      return User::whereBarcodeNumber($number)->exists();
                  }
                  

                  這篇關(guān)于如何在laravel中為每個用戶生成唯一的隨機值并將其添加到數(shù)據(jù)庫中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)
                  <i id='mfudD'><tr id='mfudD'><dt id='mfudD'><q id='mfudD'><span id='mfudD'><b id='mfudD'><form id='mfudD'><ins id='mfudD'></ins><ul id='mfudD'></ul><sub id='mfudD'></sub></form><legend id='mfudD'></legend><bdo id='mfudD'><pre id='mfudD'><center id='mfudD'></center></pre></bdo></b><th id='mfudD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mfudD'><tfoot id='mfudD'></tfoot><dl id='mfudD'><fieldset id='mfudD'></fieldset></dl></div>

                    <tfoot id='mfudD'></tfoot>
                      <bdo id='mfudD'></bdo><ul id='mfudD'></ul>
                          • <legend id='mfudD'><style id='mfudD'><dir id='mfudD'><q id='mfudD'></q></dir></style></legend>
                              <tbody id='mfudD'></tbody>
                          • <small id='mfudD'></small><noframes id='mfudD'>

                            主站蜘蛛池模板: 欧洲妇女成人淫片aaa视频 | 久久精品国产99国产 | 国产精品久久久久久久免费观看 | 91社区在线观看 | 欧美日韩成人 | 人操人人 | 91久久精品一区二区二区 | 国产一区二区三区 | 国产久 | 国产在线观看 | 99精品国产一区二区三区 | 粉嫩一区二区三区四区公司1 | 日本一区二区三区在线观看 | 狠狠涩| 精品一区二区三区在线观看国产 | 超碰97av | 午夜国产一级 | 黄频视频| 偷拍自拍网站 | 欧美精品乱码久久久久久按摩 | 麻豆精品国产91久久久久久 | 国产精品高潮呻吟久久 | 91中文在线观看 | 国产精品视频在线免费观看 | 伊人网在线看 | 欧美综合久久久 | 午夜99| 免费视频一区二区三区在线观看 | 亚洲69p| av网址在线 | 亚洲激情网站 | 麻豆天堂 | 欧一区二区 | 四虎影视在线 | 久久亚洲一区 | 午夜免费福利电影 | 国产h视频 | 手机看片1| 国产成人91视频 | 中文字幕日韩欧美一区二区三区 | 不卡一区 |