Raymart Calinao AsthreA Raymart Calinao AsthreA - 3 months ago 18
MySQL Question

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

Answer

You can use REGEXP

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