Reputation: 222
How can I select values from the MySQL database by a range of the index?
For example I have the search values of A-Be
How can I retrieve values that start with "A" ranging to "Be"
I've tried using LIKE/RLIKE but I'm only able to get the values I set and not everything in between.
$query = $db->query( "SELECT place FROM places WHERE place RLIKE '^$i[0]' AND place RLIKE '^$i[1]'" );
I'm guessing that BETWEEN would need to be used but I'm not sure where to put it.
Thanks
Upvotes: 0
Views: 86
Reputation: 28753
you can try with REGEXP like
$query = $db->query( "SELECT place FROM places WHERE place REGEXP '^$i[0]'
OR place REGEXP '^$i[1]'" );
Upvotes: 3