我可以把它放在while循环中吗? [英] Can I put this in a while loop ?
问题描述
我想为我的
客户创建一个唯一的用户ID,所以我拿前面的3个字母
名称并添加4位数字来自rand()函数
如果客户端namd是david,
这个shoud给我一些类似的东西:
$ Db_user = davi7024
现在我想检查这是一个唯一的用户ID所以
我在数据库中查找。
现在如果记录存在,我想再次使用rand
重新生成用户ID,然后重新检查。如果找到了,请再做一次,然后重新检查等。
做多次重新检查,我想我需要把
抬起来在一个循环中。
但我不知道在这种情况下如何使用while循环。
这就是我所拥有的远:
Db_user = davi7024
现在我想检查这是一个唯一的用户ID所以
我在数据库中查找它。
现在如果记录存在, 我想要 再次使用rand
重新生成用户ID,然后重新检查。如果找到了,请再做一次,然后重新检查等。
做多次重新检查,我想我需要把
抬起来在一个循环中。
但我不知道在这种情况下如何使用while循环。
这就是我所拥有的远:
展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号
我可能会通过选择所有当前的id并将它们放在1d中来实现数组。
然后就像你说的,创建一个while循环创建随机数并测试
展开 | 选择 | Wrap | 行号
如果您使用普通数字作为用户ID,则可以使用db字段的AUTO_INCREMENT选项(无需为用户ID传递任何内容)。
I am wanting to create a unique user id for my
clients, so I am taking the first 3 letters of there
name and adding the 4 digits from the rand() function
If the clients namd is david,
this shoud give me something like:
$Db_user = davi7024
Now I want to check that this IS a unique user id so
I look it up in the database.
Now if the record exists, I want to regenerate the user-id with the rand
again and then re-check. If found, do again and re-check again etc.
Do do the multiple re-checks, I guess that I need to put the
look up in a while loop.
But I am not sure how to use the while loop in this case.
This is what I have so far:
Expand|Select|Wrap|Line Numbers解决方案Db_user = davi7024
Now I want to check that this IS a unique user id so
I look it up in the database.
Now if the record exists, I want to regenerate the user-id with the rand
again and then re-check. If found, do again and re-check again etc.
Do do the multiple re-checks, I guess that I need to put the
look up in a while loop.
But I am not sure how to use the while loop in this case.
This is what I have so far:
Expand|Select|Wrap|Line Numbers
I would probably do it by SELECT all the current ids and place them in a 1d array.
Then like you say, create a while loop creating random numbers and testing
Expand|Select|Wrap|Line Numbers
if you?re fine with plain numbers as user id you can use the AUTO_INCREMENT option for the db field (no need to pass anything at all for user id).
这篇关于我可以把它放在while循环中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆