Code: Select all
$Dat = sprintf("%d-%02d-01",$Yr,$Mth);
$Var = ($_POST['Lnum'] > 0) ? $_POST['Lnum'] : $_POST['Inum']; // doing client or location
$Do = ($_POST['Lnum'] > 0) ? "lref" : "iref"; // doing client or location
mysql_select_db("Main", $Link); // select the main database
$Query = "SELECT * FROM Staff WHERE $Do=$Var AND YEAR(Date)>2000 AND Date<'$Dat'";
$res = mysql_query($Query, $Link);
mysql_select_db("ObsMain", $Link); // select the reserve database
while ($row = mysql_fetch_array($res))
{
$i = 0 + $row['id'];
$c = 0 + $row['iref'];
$l = 0 + $row['lref'];
$Query = "INSERT INTO Staff (id,iref,lref) VALUES ($i,$c,$l)";
mysql_query($Query, $Link);
}
mysql_select_db("Main", $Link); // reselect the main database
$Query = "DELETE FROM Staff WHERE $Do=$Var AND YEAR(Date)>2000 AND Date<'$Dat'";
mysql_query($Query, $Link);