I have a database which holds calendar events. On handle_events.php?load=1, I want the file to echo all the events. If things like 'start=20190121' or 'end=20190121' are appended to the url, I want the file to echo events only that are in this timeline. The solutions I have thought of were:
write the entire query in each if-else for every possible settings. -> This would be almost impossible if the options increase.
set
$query="select from sometable where first condition"
and append "AND option=value" on each option addition -> This would be acceptable on multiple options, but what if there is not a single necessary condition? then the statement would be like "~ where AND option=value" and would raise a syntax error.
These two ways both have drawbacks and look somewhat primitive. Would there be a more elegant way to do this?