Hi,
I'm having a small problem, I have a database with dates in, that users can add and update. They can open, and close dates. What I was is if they select 10th - 20th September as Open, it adds it, then if they select 9th - 18th September as Closed, it will update the original to be open from 19th - 20th, then add 9th - 18th as closed. I can get this to work fine, but its when someone then updates again, say 6th - 16th September, rather than update just record 2 to be closed on 17th - 18th September, and insert new record 6th - 16th, it also sets record 1 as 17th - 20th. I can't find anyway of getting it to update just 1 record.
Below is my code, its quite complex, used >= and <= to pull out the dates.
$sql1="SELECT * FROM availability WHERE user_id='$sUserID' AND room_code='$sRoomcode' AND start_date>='$start_new' && start_date<='$end_new' && end_date>='$end_new'";
$result=db_query($sql1);
if ($result) {
$row = mysql_fetch_row ($result);
if (!$row1[0] == 0) {
$sql2="UPDATE availability SET start_date='$end_new'+1";
$result2=db_query($sql2);
$sql3="INSERT INTO availability (user_id,room_code,status,start_date,end_date) ".
"VALUES ('$sUserID','$sRoomcode','$status','$start_new','$end_new')";
$result3=db_query($sql3);
$feedback .= " Successfully Updated 1st Availability. You Will Receive a Confirmation Email Soon ";
}
}
I'd be very greatful if someone code let me know if i'm doing anything wrong.
Many Thanks
Ben