php - 查找字段的某位数相同的数据
PHPz
PHPz 2017-04-10 17:32:36
0
1
297

想要查找uid倒数第二位的数值一样的数据
比如
1000000005
1000000006
1000000007
1000000008
1000000023 //不同的不要
1000000009

要实现这样的逻辑,怎么办

$uid = I('get.uid', 0, 'intval');//假设用户ID:1000000005
$where['uid'] = substr($uid, -2,1);//倒数第二位:0
$res = M('code')->where($where)->select();//这样做实现不了
PHPz
PHPz

学习是最好的投资!

全部回覆(1)
Ty80
$where['uid'] = 'substr('+$uid+', -2,1)';

加上引号试一下,不加引号变成php中的函数了,mysql 也有substr函数的

你要生成的是类似这样的语句

select * from `character` where SUBSTR(characterId, -2,  1) ='1'
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板