Php 如何基于first&;姓
我需要遍历数据库中的每一个,并给它们一个独特的3/4字母股票符号,如代码 我有大约600个人名,我想为所有人生成股票符号,比如唯一的代码,但基本上是基于人名(比如股票符号) 例如: Dale Cooper可以是DCO/DAC/DC,但Darren Cooper应该生成不同的代码,因为所有600个都应该是唯一的 名字和姓氏在不同的列中Php 如何基于first&;姓,php,Php,我需要遍历数据库中的每一个,并给它们一个独特的3/4字母股票符号,如代码 我有大约600个人名,我想为所有人生成股票符号,比如唯一的代码,但基本上是基于人名(比如股票符号) 例如: Dale Cooper可以是DCO/DAC/DC,但Darren Cooper应该生成不同的代码,因为所有600个都应该是唯一的 名字和姓氏在不同的列中 非常感谢您的建议。为了简单起见,可以用4个字母: First letter: first letter of firstname Second letter: l
非常感谢您的建议。为了简单起见,可以用4个字母:
First letter: first letter of firstname
Second letter: letter of the alphabet (starting with `A` keeping count)
Third letter: first letter of lastname
Fourth letter: letter of the alphabet (starting with `A` keeping count)
这样,每个名字都有1*26*1*26=676
可能性,Dale Cooper或Darren Cooper将是676中的两个,即:
Dale Cooper DACA
Darren Cooper DACB
Douglas Cooper DACC
当第四个字母到达Z
时,第二个字母得到B
:
Dave Cooper DACZ
Doctor Cooper DBCA
等等
编辑
为了使字母代码中的名称更直观,您还可以使用:
First letter: first letter of firstname
Second letter: first letter of lastname
Third letter: letter of the alphabet (starting with `A` keeping count)
Fourth letter: letter of the alphabet (starting with `A` keeping count)
坚持使用mysql:
UPDATE people
SET code = CONCAT(
SUBSTRING(first_name, 1, 1),
SUBSTRING(last_name, 1, 1),
SUBSTRING( MD5( CONCAT(first_name, last_name) ), 1, 2)
)
你会得到:
- 名字的第一个字母李>
- 姓氏的第一个字母李>
- 姓名+姓氏的前2个字母李>