tags:

views:

36

answers:

2

Hello,

The query below works well. I would like to use it for search results now. I would like to have it return the same results with this one modification:

The field s.title has the variable $find somewhere in it. I. e., the field s.title. doesn't have to exactly equal $find, but it must have a word in it that equals $find.

How can I do this?

Thanks in advance,

John

$sqlStr = "SELECT s.loginid, s.title, s.url, s.displayurl, s.datesubmitted, l.username,
  s.submissionid, COUNT(c.commentid) countComments, 
  GREATEST(s.datesubmitted, COALESCE(MAX(c.datecommented), s.datesubmitted)) AS most_recent
FROM submission s
INNER JOIN login l ON s.loginid = l.loginid
LEFT OUTER JOIN comment c ON s.submissionid = c.submissionid
GROUP BY s.submissionid
ORDER BY most_recent DESC
LIMIT $offset, $rowsperpage";
+1  A: 
$sqlStr = "...WHERE s.title LIKE '%" . $find . "%'";

LIKE uses wildcards to match values

adam
Note to OP - be careful: This could vulnerable to SQL injections.
Mark Byers
A: 

Just add the following line before GROUP BY clause:

WHERE s.title LIKE '%" . mysql_real_escape_string($find) . "%'
vadimbelyaev