开发者

how to find if table column value has a number in it and generate the results [duplicate]

开发者 https://www.devze.com 2023-03-23 20:55 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: MySQL - Check if a string contains numbers
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

MySQL - Check if a string contains numbers

This is a difficult search considering it's something that seems pretty common. What I'm trying to do is do a query finding the value a column in a database table and checking if it contains any numbers and grab the results to display开发者_如何学Python in a foreach loop.

The code I have now is to generate results by a particular letter:

$sql = "SELECT * FROM table WHERE value LIKE '{$letter}%' ORDER BY value;"; 
    $query = $this->db->query($sql);//Codeigniter function

Could I do something like:

$sql = "SELECT * FROM table WHERE value LIKE '%#%' ORDER BY value;"; 
    $query = $this->db->query($sql);

I apologize if this is a super easy question. I'm a bit of a n00b. Any advice is greatly appreciated. Thanks in advance.


see the answer posted here. Check if a string contains numbers

SELECT * FROM table WHERE tag REGEXP '[0-9]'


$sql = "SELECT * FROM table WHERE value REGEXP '\d' ORDER BY value;"; 

this will display only records with digit in it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号