Search by LIKE
Posted: Fri Oct 01, 2004 10:23 am
I have a query that queries for 1 column ("common") with three separate variables ("search1, search2, search3"). Here is my query with actual words instead of variables:
This works fine. The "word1, word2, word3" will actually be variable results.
So I tried making the variables which are pulled from another query record ("detailsDoctrine") and then do the query above with the variables:
That does not work. What am I doing wrong?
Code: Select all
<?php
SELECT * FROM con_doctrines WHERE common LIKE '%word1%' OR common LIKE '%word1%' OR common LIKE '%word2%'
?>So I tried making the variables which are pulled from another query record ("detailsDoctrine") and then do the query above with the variables:
Code: Select all
<?php
$search1 = "%" . $row_detailsDoctrine['search1'] . "%";
$search2 = "%" . $row_detailsDoctrine['search2'] . "%";
$search3 = "%" . $row_detailsDoctrine['search3'] . "%";
SELECT * FROM con_doctrines WHERE common LIKE $search1 OR common LIKE $search2 OR common LIKE $search3
?>