English 中文(简体)
如何制定独特的守则
原标题:How to generate a unique code

我与我的亚洲开发银行和用户联系,提交电子邮件地址。 储存在亚洲开发银行。 这是我从动荡中挑选出来的。

I d like a user-unique code generated through JS on document load.. Format should be 6 digits in length and only using only A-Z and 0-9. ie: F4DRB6

Once that is done I d need to store that unique code for that user in the DB.
The generator should check if the unique code exists in the DB, to ensure it is actually unique.

我的麻烦在于:我不知道如何以上述格式制定独特的守则,检查它是否有别于非行,然后将其存放在与该用户相称的非行。 下面是一栏,与浏览量相对应?

感谢!

www.un.org/Depts/DGACM/index_spanish.htm EDIT:我试图这样做,如果有任何错误,请注明。 附录

function genRandomString() {
    $length = 5;
    $characters =  1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ ;
    $string =   ;    

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

do {
  $random_string = $this->genRandomString();
} while (mysql_num_rows(mysql_query("SELECT referralcode FROM ".coming_soon_emails." WHERE rand_string= {$random_string} ")));
$q = "INSERT INTO ".coming_soon_emails." SET referralcode= {$random_string} ";
$result = mysql_query($q);
问题回答

为什么需要在客户方面创造? 为什么当客户提交“最后”表格时,你才可以制定守则?

http://php.net/manual/en/Function.rand.php 页: 1 如果你出现违约错误,你就会再制造,再次尝试。

但这也是这样做的方法之一。

Its simple math, 6^36 is large enough that creating a random id is mostly unique.

如果您的大麻是100%,则使用美国宇宙航空研究开发机构对数据库中产生的识别资料进行检查,如果存在的话,则予以重新计算。

In a causal way, a simple walk-through would be:

a) 我sql 书写:

首先,产生一种随机代码,如Abius 十说,这取决于你的用户群大小,可能很少使用新的代码。

这将为你们带来一种天候,并应当让你们开始。

SlectT conv(FLOOR(RAND(16)),10,16);

Then you will need to check if this code has been used already. `

SELECT * FROM usertable where code = generatedcode

如果是,会产生新的变化。

在更强有力的环境下,我总是先制定独特的守则,将其储存在“未使用守则”表格中,因此,我只能 gr弃任何法典,确保它具有独特性,而不是使用。

下面的java成文是一种独特的错误代码生成器,其复制法的可能性极小。 因此,除了记录在印发时所用的代码外,你无需跟踪已经使用的代码。 你们可以在我的网站上通过浏览“Unique Error Code”发电机(在你搜寻时使用引语)。

function convertTimeRandToBase36() {
    const currentDate = new Date();               // Get the current date and time
    const milliseconds = currentDate.getTime();   // Get the millisecords since Jan 1, 1970
    const base36Time = milliseconds.toString(36); // Convert milliseconds to base 36
    // generate a random number between 100 thousand and a billion
    let random1 = 0;
    let random2 = 0;
    let random3 = 0;
    let random = 0;
    while (random < 100000) {
      random1 = Math.floor(Math.random() * 1000);
      random2 = Math.floor(Math.random() * 1000);
      random3 = Math.floor(Math.random() * 1000);
      random = random1 * random2 * random3;
    }
    base36Random = random.toString(36);  // Convert random to base 36
    let uniqueErrorCode = base36Time + base36Random;
    uniqueErrorCode = uniqueErrorCode.toUpperCase();
    return uniqueErrorCode;
}
console.log("Unique Error Code:", convertTimeRandToBase36());




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签