I'm trying to use PHP to query MYSQL for some exact matches and some partial matches. The following code give me perfect exact matches for all fields:
$results= mysql_query ("SELECT *
FROM companyinfo
WHERE id='$Companyid'
OR companyname='$Companyname'
OR contactname='$Contactname'
OR address1='$Address1'
OR city ='$City'
OR primaryphone='$Primaryphone'
OR email='$Email'")
I would like to be able to do a partial search on Company Name. Using the following code allows me to achieve this except it messes up all other search fields.
$results= mysql_query ("SELECT *
FROM companyinfo
WHERE id='$Companyid'
OR companyname LIKE '%{$Companyname}%'
OR contactname='$Contactname'
OR address1='$Address1'
OR city ='$City'
OR primaryphone='$Primaryphone'
OR email='$Email'")
Anyone have any hints?
See Question&Answers more detail:os