Hi all, I've been working on an hourregistrationprogram for a company, but when I try to make a search option, I get completely stuck.
This is my setup:
There are 4 fields:
Naam
Klant
Onderdeel
Bezigheid
The fields can be either a set value or any of the values in a mysql database. For example:
Name: can be set value (in my case Alle Werknemers) or it can be a value from the database, so each field has 2 possibilities.
This is with all my 4 fields.
The problem is, the value of these fields decides the query that will be run. If all the fields are the set value, it will run a SELECT * query on the entire database without using the WHERE naam=$naam AND klant=$klant etc....
The really big problem (if you can follow all I've said before..🙂) is that the if statement stuff is getting extremely big and i don't know what to do with it anymore!
Here is some of the code (not even sure if it's right damnit): (not even half of it i reckon...since there are 16 different possibilities between them (naam can be two values, klant can be two values, so 2x2x2x2=16 possibilities!!.
All the 'alle ...' are the set values.. so if naam does not equal the set value, etc)....
if ($naam!='Alle Medewerkers')
{
if($klant!='Alle Klanten')
{
if($onderdeel!='Alle Onderdelen')
{
if($bezigheid!='Alle Bezigheden')
{
$sql=mysql_query("SELECT FROM urenregistratie WHERE naam='$naam' AND klant='$klant' AND onderdeel='$onderdeel' AND bezigheid='$bezigheid' AND mktimestop!=''AND week BETWEEN '$weekbegin' AND '$weekeind' ORDER BY naam ASC, klant ASC, onderdeel ASC, bezigheid ASC, datum ASC ")
or die("Query fout");
}
else
{
if ($naam!='Alle Medewerkers')
{
if($klant!='Alle Klanten')
{
if($onderdeel!='Alle Onderdelen')
{
$sql=mysql_query("SELECT FROM urenregistratie WHERE naam='$naam' AND klant='$klant' AND onderdeel='$onderdeel' AND mktimestop!=''AND week BETWEEN '$weekbegin' AND '$weekeind' ORDER BY naam ASC, klant ASC, onderdeel ASC, bezigheid ASC, datum ASC ")
or die("Query fout");
}
else
{
if ($naam!='Alle Medewerkers')
{
if($klant!='Alle Klanten')
{
$sql=mysql_query("SELECT * FROM urenregistratie WHERE naam='$naam' AND klant='$klant' AND mktimestop!=''AND week BETWEEN '$weekbegin' AND '$weekeind' ORDER BY naam ASC, klant ASC, onderdeel ASC, bezigheid ASC, datum ASC ")
or die("Query fout");
}
else
{ etc etc...
isn't there a better way of doing this?? Since I'm completely lost now..........
PLEASE HELP ME.....I would really appreciate it..
thanks,
Menno