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
精彩评论