I have written a SQL select statement to search any of four fields in my database. This works OK, but returns every entry that includes the Parish 'Kilmacolm' in addition to the relative site in question.
The five fields are:
Site Name, Parish, Site Type and Map.
What I want to be able to do is enter any number of variables and retrieve only the relevant Sites.
Is there a simple way to do this?
Thanks in advance
Stephen
My current code is:
--------------------
$sql = "SELECT id, SiteName, Parish, SiteType, Map
FROM $table_name
where (SiteName=\"$site\" or Parish=\"$parish\" or SiteType=\"$sitetype\" or Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\")
or (SiteName=\"$site\" and SiteType=\"$sitetype\")
or (SiteName=\"$site\" and Map=\"$map\")
or (Council=\"$coun_in\" and SiteType=\"$sitetype\")
or (Council=\"$coun_in\" and Map=\"$map\")
or (SiteType=\"$sitetype\" and Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\" and SiteType=\"$sitetype\")
or (SiteName=\"$site\" and Parish=\"$parish\" and Map=\"$map\")
or (SiteName=\"$site\" and SiteType=\"$sitetype\" and Map=\"$map\")
or (Council=\"$coun_in\" and SiteType=\"$sitetype\" and Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\" and SiteType=\"$sitetype\" and Map=\"$map\")
ORDER BY SiteName
";
--------------
The five fields are:
Site Name, Parish, Site Type and Map.
What I want to be able to do is enter any number of variables and retrieve only the relevant Sites.
Is there a simple way to do this?
Thanks in advance
Stephen
My current code is:
--------------------
$sql = "SELECT id, SiteName, Parish, SiteType, Map
FROM $table_name
where (SiteName=\"$site\" or Parish=\"$parish\" or SiteType=\"$sitetype\" or Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\")
or (SiteName=\"$site\" and SiteType=\"$sitetype\")
or (SiteName=\"$site\" and Map=\"$map\")
or (Council=\"$coun_in\" and SiteType=\"$sitetype\")
or (Council=\"$coun_in\" and Map=\"$map\")
or (SiteType=\"$sitetype\" and Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\" and SiteType=\"$sitetype\")
or (SiteName=\"$site\" and Parish=\"$parish\" and Map=\"$map\")
or (SiteName=\"$site\" and SiteType=\"$sitetype\" and Map=\"$map\")
or (Council=\"$coun_in\" and SiteType=\"$sitetype\" and Map=\"$map\")
or (SiteName=\"$site\" and Parish=\"$parish\" and SiteType=\"$sitetype\" and Map=\"$map\")
ORDER BY SiteName
";
--------------