所以我有这个问题:
$sql = "SELECT name FROM table1 WHERE name LIKE '%$search%'".
"UNION ".
"SELECT name FROM table1 WHERE name LIKE '%".$pieces[0]." ".$pieces[1]."%'".
"UNION ".
"SELECT name FROM table1 WHERE name LIKE '%".$pieces[0]." ".$pieces[2]."%' ORDER BY name";
我希望第一个查询的结果在列表中排在第一位,然后其余的按字母顺序排列。我怎么做到这一点?
答案 0 :(得分:0)
除了明显的SQL注入注释
$sql = "Select 1 as x, name from table1 where name like '%$search$' ".
"UNION "
"SELECT 2 as x, name FROM table1 WHERE name LIKE '%".$pieces[0]." ".$pieces[1]."%' ".
"UNION ".
"SELECT 2 as x, name FROM table1 WHERE name LIKE '%".$pieces[0]." ".$pieces[2]."%' ".
" ORDER BY x, name";
这将首先按顺序排序第一个查询,然后按字母顺序排列第二个
如果您希望所有三个按顺序在第三个查询中将2更改为3。