filter result of mysql by numerical

I would like to filter the result of first character by any numerical(0-9)

in filtering by letters i use this code

$letter="A";
$stmt = $db->prepare("SELECT * FROM pages WHERE LEFT(`title`, 1)='$letter' order by title ASC  LIMIT :limit, :perpage");


if i tried to change the value of variable $letter to '0' it only returns all the results character starting 0..if possible i would like to get all the numerical value

my goal was to create a navigator filtering them all by letter and number like this one
enter image description here

Upvotes: 2

Views: 42

Answers (1)

1000111
1000111

Reputation: 13519

You can use REGEXP

SELECT * 
FROM pages 
WHERE title REGEXP '^[0-9]'
ORDER BY title ASC;

Explanation:

^ means start with

[0-9] characters (0 or 1 or 2....to 9) inside this subscripts

Upvotes: 4

Related Questions