Php 使用列表中的随机链接更新列

Php 使用列表中的随机链接更新列,php,mysql,sql,Php,Mysql,Sql,我有一个名为users的数据库表(25k条记录) 里面有一个叫做“阿凡达”的区域 我需要从列表中分配一个随机url来更新此字段 列出URL: http://myserver.com/img/1.png http://myserver.com/img/2.png http://myserver.com/img/3.png http://myserver.com/img/4.png http://myserver.com/img/5.png http://myserver.com/img/6.png

我有一个名为users的数据库表(25k条记录)

里面有一个叫做“阿凡达”的区域

我需要从列表中分配一个随机url来更新此字段

列出URL:

http://myserver.com/img/1.png http://myserver.com/img/2.png http://myserver.com/img/3.png http://myserver.com/img/4.png http://myserver.com/img/5.png http://myserver.com/img/6.png http://myserver.com/img/7.png http://myserver.com/img/8.png http://myserver.com/img/9.png http://myserver.com/img/10.png http://myserver.com/img/11.png http://myserver.com/img/12.png http://myserver.com/img/13.png http://myserver.com/img/14.png http://myserver.com/img/15.png
如何调整此查询?

您正在寻找类似的查询吗

更新用户
设置化身=CONCAT('http://myserver.com/img/,地板(1+RAND()*15),“.png”);
这里是演示


虽然我建议只存储整数部分,但如果需要存储

更新用户
设置头像=地板(1+RAND()*15);
选择id,CONCAT('http://myserver.com/img/,头像,'.png')头像
来自用户;
这里是演示

然后,当你选择你的数据时,或者最好在你的客户端代码中创建一个动态的化身url(从某种设置中获取域名和路径)

选择id,CONCAT('http://myserver.com/img/,地板(1+RAND()*15),'.png')头像
来自用户;

以下是演示

如果您的图像遵循良好的模式,@peterm给出的答案是好的,但是您也可以从列表中选择一个随机字符串:

SELECT ELT(ROUND(0.5+RAND()*15), 
 'http://myserver.com/img/1.png',
 'http://myserver.com/img/2.png',
 'http://myserver.com/img/3.png',
 'http://myserver.com/img/4.png',
 'http://myserver.com/img/5.png',
 'http://myserver.com/img/6.png',
 'http://myserver.com/img/7.png',
 'http://myserver.com/img/8.png',
 'http://myserver.com/img/9.png',
 'http://myserver.com/img/10.png',
 'http://myserver.com/img/11.png',
 'http://myserver.com/img/12.png',
 'http://myserver.com/img/13.png',
 'http://myserver.com/img/14.png',
 'http://myserver.com/img/15.png') AS avatar;

要更新表,可以在update语句中使用相同的
ELT()
表达式:

UPDATE TABLE SET AVATAR=ELT(...);

什么是列表url、数组和列?请更具体一些。