在表格中,我使用full_name列的格式为"名字姓氏"
EG。 " John West"
我用这个:
$q="John";
$sql = "SELECT full_name FROM wp_users where full_name like '$q%' order by display_name ASC";
这没关系," John West"退回。
但如果我让$ q等于" West"并尝试通过姓氏搜索然后没有任何返回。是否有一个mysql语句可以用来更好地做到这一点?
答案 0 :(得分:1)
尝试使用适当的wildchar concat来处理你的病情
$sql = "SELECT full_name
FROM wp_users where full_name like concat('%', $q,'%')
ORDER BY display_name ASC";
或
$q = '%John%';
$sql = "SELECT full_name
FROM wp_users where full_name like '$q'
ORDER BY display_name ASC";
答案 1 :(得分:0)
双方放百分比
$q="John";
$sql = "SELECT full_name FROM wp_users where full_name like '%$q%' order by display_name ASC";
答案 2 :(得分:0)
你试过
吗?$q="John";
$sql = "SELECT full_name FROM wp_users where full_name like '$q%' or full_name like '$%q' order by display_name ASC";