基本上我是用php和MySQL从头开始创建一个社交网络CMS
我需要搜索工作,搜索用户的用户名,显示名称和电子邮件,以返回上述任何结果
<?php require('core.common.php');
//Search page php
$sq = htmlspecialchars($_GET['q'], ENT_QUOTES);
$search = $db->prepare("SELECT username, disp_name, profilepic
FROM users WHERE username OR disp_name OR email LIKE '%sq%';");
$search->execute();
$viewsearch = $search->fetchAll();
我已经尝试了这个,但一次只能在一列上运行:
$search = $db->prepare("SELECT username, disp_name, profilepic
FROM users WHERE username LIKE '%$sq%';");
我已经尝试过了......
"SELECT username, disp_name, profilepic FROM users WHERE username LIKE '%sq%'OR disp_name LIKE '%sq%'OR email LIKE '%sq%' ORDER BY username;"
和
"SELECT username, disp_name, profilepic FROM users WHERE ((username LIKE '%sq%') OR (disp_name LIKE '%sq%') OR (email LIKE '%sq%'));"
除了以上几种变体之外,仍然没有希望。
答案 0 :(得分:3)
SELECT username, disp_name, profilepic
FROM users
WHERE username LIKE '%sq%'
OR disp_name LIKE '%sq%'
OR email LIKE '%sq%'
答案 1 :(得分:2)
我认为您正在寻找的是:
SELECT username, disp_name, profilepic
FROM users
WHERE username LIKE '%sq%'
OR disp_name LIKE '%sq%'
OR email LIKE '%sq%';