I am trying to perform a query against a database with a combination of OR conditions. By filling out the form with corresponding fields in the database, after receiving the data, I put the query in such a way:
if ($state != '') {
$xstate = " `State` LIKE '%" . $state . "%' ";
$Isall = '0';
} else {
$xstate=" `State` LIKE '-' ";
}
if ($dateStart != '' && $dateEnd != '') {
$xdateStart = " `datefill` BETWEEN '" . $dateEnd . "' AND '" . $dateStart . "'";
echo $xdateStart;
$Isall = '0';
}
as you can see, I check if the field is empty or not then I start to build the query, after asking all the relevant questions the query will look like:
$query="SELECT " .$field . " FROM issueslog WHERE ".$xdateStart." OR " .$xCode ." ;
and so on, my problem now is when I fill some field, for example xCode now is with data let say "900" and dateStart as you can see above is
$xdateStart=" datefill BETWEEN '".$dateEnd."' AND '".$dateStart."'";
so what I`m understood is that it will fetch data that corresponde to the code "900" between the specific dates, but what I get is result that coressponde only the the xCode 900, its seems that the date was abandoned.
I'd like to get suggestions, Thanks in advance.
EDIT
My generated query is:
SELECT * FROM issueslog WHERE `datefill` BETWEEN '2013-05-24' AND '2013-05-24' OR `xCode` LIKE '-' OR `Address` LIKE '-' OR `tname` = '-' OR `fname` LIKE '-' OR `Phone1` LIKE '-' OR `State` LIKE '-' OR `City` LIKE '%TelAviv%'