本文介绍了我可以把它放在while循环中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想为我的 客户创建一个唯一的用户ID,所以我拿前面的3个字母 名称并添加4位数字来自rand()函数 如果客户端namd是david, 这个shoud给我一些类似的东西: $ Db_user = davi7024 现在我想检查这是一个唯一的用户ID所以 我在数据库中查找。 现在如果记录存在,我想再次使用rand 重新生成用户ID,然后重新检查。如果找到了,请再做一次,然后重新检查等。 做多次重新检查,我想我需要把 抬起来在一个循环中。 但我不知道在这种情况下如何使用while循环。 这就是我所拥有的远: 展开 | 选择 | Wrap | 行号 解决方案 Db_user = davi7024 现在我想检查这是一个唯一的用户ID所以 我在数据库中查找它。 现在如果记录存在, 我想要 再次使用rand 重新生成用户ID,然后重新检查。如果找到了,请再做一次,然后重新检查等。 做多次重新检查,我想我需要把 抬起来在一个循环中。 但我不知道在这种情况下如何使用while循环。 这就是我所拥有的远: 展开 | 选择 | Wrap | 行号 我可能会通过选择所有当前的id并将它们放在1d中来实现数组。 然后就像你说的,创建一个while循环创建随机数并测试 展开 | 选择 | Wrap | 行号 如果您使用普通数字作为用户ID,则可以使用db字段的AUTO_INCREMENT选项(无需为用户ID传递任何内容)。 I am wanting to create a unique user id for myclients, so I am taking the first 3 letters of therename and adding the 4 digits from the rand() functionIf the clients namd is david,this shoud give me something like:$Db_user = davi7024Now I want to check that this IS a unique user id soI look it up in the database.Now if the record exists, I want to regenerate the user-id with the randagain 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 thelook 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 = davi7024Now I want to check that this IS a unique user id soI look it up in the database.Now if the record exists, I want to regenerate the user-id with the randagain 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 thelook 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 NumbersI 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 Numbersif 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循环中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 01:41