php和sql的新手,所以我将尝试解释:
我在PHP中有一个SEARCH字段,我试图通过与用户输入的内容匹配的'ProposalName'进行搜索。
打印得很好:
SELECT
rec_proposal.ProposalID,
ProposalName,
Status,
researcher.FirstName,
researcher.LastName,
reviewer.FirstName as revFirstName,
reviewer.LastName as revLastName,
reviewer.UserID as revUserID,
review.ReviewDate as revDate,
rec_proposal.DateSubmitted
FROM rec_proposal
INNER JOIN User AS researcher
ON rec_proposal.userid = researcher.UserID
LEFT JOIN review
ON rec_proposal.ProposalID=review.ProposalID
LEFT JOIN User as reviewer
ON review.UserID=reviewer.UserID
但是现在使用所有列我需要上面的代码来做这样的事情
SELECT * FROM rec_proposal WHERE CONCAT (ProposalName) LIKE'%test%'
如果用户输入单词'test',您会看到包含单词test
的ProposalName答案 0 :(得分:0)
只需添加您的WHERE
子句即可。正如scaisEdge在评论中指出的那样,如果您只评估一个列,则不需要CONCAT()
:
SELECT
rec_proposal.ProposalID,
ProposalName,
Status,
researcher.FirstName,
researcher.LastName,
reviewer.FirstName as revFirstName,
reviewer.LastName as revLastName,
reviewer.UserID as revUserID,
review.ReviewDate as revDate,
rec_proposal.DateSubmitted
FROM rec_proposal
INNER JOIN User AS researcher
ON rec_proposal.userid = researcher.UserID
LEFT JOIN review
ON rec_proposal.ProposalID=review.ProposalID
LEFT JOIN User as reviewer
ON review.UserID=reviewer.UserID
WHERE rec_proposal.ProposalName LIKE '%test%'