Find data with the same number of bits in a field

Source: Internet
Author: User
You want to find the same data as the second-to-last value of the UID
Like what
1000000005
1000000006
1000000007
1000000008
1000000023//different do not
1000000009

To implement such logic, what to do

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

Reply content:

You want to find the same data as the second-to-last value of the UID
Like what
1000000005
1000000006
1000000007
1000000008
1000000023//different do not
1000000009

To implement such logic, what to do

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

$where['uid'] = 'substr('+$uid+', -2,1)';

Add quotation marks to try, do not add quotation marks into PHP function, MySQL also has the SUBSTR function

You're going to generate a statement like this.

select * from `character` where SUBSTR(characterId, -2,  1) ='1'
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.