Youjoomla Support Forums (http://www.youjoomla.com/joomla_support/index.php)
-   Anything Goes (http://www.youjoomla.com/joomla_support/forumdisplay.php?f=31)
-   -   Help with code please (http://www.youjoomla.com/joomla_support/showthread.php?t=3986)

treehugger 07-26-2009 02:21 PM

Help with code please
 
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!

ameenudeen 10-13-2009 09:58 AM

Try to use mysql_fetch_array($result)............ and diplay the results............


All times are GMT -4. The time now is 04:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.