Code:
hello guys, im screwed as ive got no idea how to do this:

ive got two tables:

EMPLOYEES
id_employee	name
-----------------------
1		George
2		John
3		Peter
4		Martin


CONTRACTS
id_contract	id_employee	date_start	date_finish
------------------------------------------------------------
1		1		1.10.09		5.10.09
2		1		6.10.09		20.12.09
3		2		2.10.09		5.10.09
4		3		20.12.09	25.12.09
5		4		3.10.09		12.12.09

and now, ive got $show (can be 1, 2 or 0) and need any query or multiple query to select

if $show=1 means id like to select from contracts table only those whos date_finish>time()
if $show=2 means id like to select from contracts table only those whos date_finish<time()
if $show=0 then can select all of them without making difference


so far ive got:

Code:
      if($show==0) { $where = "1"; }
  elseif($show==1) { $where = "date_finish>".time(); }
  elseif($show==2) { $where = "date_finish<".time(); }

  echo "<select name=id_employee>";
  echo "<option value=0>Choose</option>";


  $result = mysql_query("SELECT * FROM evas_contracts WHERE $where GROUP BY id_employee", $connection);
  while($record = mysql_fetch_array($result))
 {
   $id_employee = $record["id_employee"];
   $date_finish = $record["date_finish"];
   
      $result2 = mysql_query("SELECT * FROM evas_employees WHERE id_employee=$id_employee ORDER BY name_first,name_last", $connection);
      while($record2 = mysql_fetch_array($result2))
     {
       $name = $record2["name"];
       
       echo "<option value=".$id_employee; if($employee==$id_employee) { echo " selected"; } echo ">".$name."</option>";       
     }     
 }

but the thing is, if you have a look on first two rows in contracts table, then you will see that both rows are ok with query, if i ask for date_finish>time() then it shows me first row, but if i ask for date_finish<time() then it comes with the otherone....

and what i simply need is, if i ask for date_finish<time() and there is any insert in contracts table for the other option already, then show it only in that1, and not in boths....

soz for my english anyway, but hope you do understand what im after