select a.studentid, CONCAT(a.firstname,' ',a.middlename,' ',a.lastname) AS studentname, a.birthdate,b.admissiondate,b.status,c.facultyname,d.classname,e.sectionname
from studentpersonalinfo as a, studentacademicinfo as b, faculty as c, class as d, section as e
WHERE a.studentid=b.studentid AND b.facultyid=c.facultyid AND b.classid=d.classid AND b.sectionid=e.sectionid AND b.status='running' and studentname LIKE '%$name%' ORDER BY $sort $order limit $offset,$rows
答案 0 :(得分:1)
我已将WHERE Condition
替换为studentname LIKE '%$name%'
CONCAT_WS(' ', a.firstname,a.middlename,a.lastname) LIKE '%$name%'
。
CONCAT_WS的一般语法是:
CONCAT_WS (separator, string1, string2,…)
现在它应该有效:
SELECT a.studentid, CONCAT(a.firstname,' ',a.middlename,' ',a.lastname) AS studentname, a.birthdate, b.admissiondate, b.status, c.facultyname, d.classname, e.sectionname
FROM studentpersonalinfo as a, studentacademicinfo as b, faculty as c, class as d, section as e
WHERE a.studentid = b.studentid AND b.facultyid = c.facultyid AND b.classid = d.classid AND b.sectionid = e.sectionid AND b.status = 'running' and CONCAT_WS(' ', a.firstname, a.middlename, a.lastname) LIKE '%$name%' ORDER BY $sort $order limit $offset, $rows
它也可以像你一样使用它,只需将CONCAT
从SELECT
替换为CONCAT_WS(' ', a.firstname, a.middlename, a.lastname) AS studentname
所以一般来说你的代码应该是:
SELECT a.studentid, CONCAT_WS(' ', a.firstname, a.middlename, a.lastname) AS studentname, a.birthdate, b.admissiondate, b.status, c.facultyname, d.classname, e.sectionname
FROM studentpersonalinfo as a, studentacademicinfo as b, faculty as c, class as d, section as e
WHERE a.studentid = b.studentid AND b.facultyid = c.facultyid AND b.classid = d.classid AND b.sectionid = e.sectionid AND b.status = 'running' and studentname LIKE '%$name%' ORDER BY $sort $order limit $offset, $rows
现在它应该正常工作......
有关详细信息,请参阅:https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws