I'm trying to run a report from a MySQL database, based on a number of parameters, which is working fine if you want to return one specific result. I want to return a range of results in which any fields left blank return all results. The report code I have is pretty simple:
PHP Code:
//define strings
$StartDate=$_GET['requiredStartDate'];
$EndDate=$_GET['requiredEndDate'];
$Analyst=$_GET['Analyst'];
$Assist=$_GET['Assist'];
$Incident=$_GET['Incident'];
$Process=$_GET['Process'];
$Service=$_GET['Service'];
//define query
$query = "SELECT Date, Incident, Analyst, Assist, Process, Service
FROM data
where Date between ('$StartDate') and ('$EndDate')
and Incident LIKE ('$Incident')
and Process LIKE ('$Process')
and Service LIKE ('$Service')
and Assist LIKE ('$Assist')
and Analyst LIKE ('$Analyst')
Order by date";
//run query and error reporting
$result = mysql_query($query) or die(mysql_error());
there's a bit more to the file but only to add the results to a table and echo them to HTML.
I've worked around the problem by having the HTML form return a wildcard when a field is blank (well, added default values and some overly complicated javascript) so it now works but it's still a bit of a hack and slash job. I just don't know enough PHP to get it to work on the server side code. I did try using an IFNULL statement on a query running between the string definition and the current query but that returned no erorrs and did nothing what-so-ever!