我有这个MySQL查询,我希望在前端点击相关字母后获取正确的艺术家。现在也有艺术家以数字开头,所以我想排除它们。即使现在,无论如何都会以数字开头的艺术家进行展示,所以我认为我的MySQL查询是错误的。
$sql = "SELECT artist_id, formated_name FROM artists WHERE formated_name LIKE '".$letter."%' OR formated_name LIKE '0%' OR formated_name LIKE '1%' OR formated_name LIKE '2%'
OR formated_name LIKE '3%' OR formated_name LIKE '4%' OR formated_name LIKE '5%' OR formated_name LIKE '6%' OR formated_name LIKE '7%'
OR formated_name LIKE '8%' OR formated_name LIKE '9%' OR formated_name LIKE '#%'";
有人可以帮助我吗?提前谢谢......
答案 0 :(得分:0)
你可以这样做:
$sql = "SELECT artist_id, formated_name FROM artists
WHERE formated_name LIKE '".$letter."%'
AND LEFT(formated_name, 1) NOT IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')";
答案 1 :(得分:0)
$sql = "SELECT artist_id, formated_name FROM artists
WHERE formated_name LIKE '".$letter."%'
这只会返回以您的信件开头的结果。