Forum Moderators: coopster
There is only one thing i couldn't handle easly and its about the date because i'm not so expert dealing with the dates funcitions so i used this to do what i need to do
my application is online at www.example.com its a test domain that i use to test my applications at
go to the www.example.com/room_chart.com and this is what its all about
1- the mysql table contains al the information about the room notice that there is a primary key which is booking_reference which i made as an auto coloumn.
2- this page table reads the mysql database and the problem is as follows
for example if you have 2 booking 1 at the beginning of the month like 1/12/2009 and then another after at 5/12/2009 it will take only the second one and if you added a third one it will take the third one
here is my my function that i use to out put the date to the table in case if this day is booked then it will output the customer name in orange color and if not it will out but available in green to show that there is no booking for this date.
function getbooking($id,$day,$month,$year){ as you can see the function takes 4 arrguments from the table cell id, day, month, year. id is the room number because the page wouldn't read the day automatically and any way this is not a matter talking about the 4 arguments the function takes them break the days into time so i can compare them and then returns an output but it only returns one and only one booking for example take the first raw in the page if you set the month to 12 and the year to 2009 now you have 2 bookings first booking 1/12/2009 you can go to www.example.com/room_statistics.php and press room 101 and you will see 2 bookings. now back to the first raw of the table room no101 this should return the output with the customers name and the room no but it doesn't every cell with this function should get back with the customer name and the room NO so the table should show this from the arrival date to the departure date the cell that shows this is the fifth cell because it matches the query if you used the same function <?php echo getbooking(101,5,12,2009); ?> so i need to know what is the problem really the i use the same function <?php echo getbooking($id,$day,$month,$year); ?> in each cell so if it matches it should i need to know why do the query in mysql returns only one booking and ignores the rest of them and it will be alwayes the newest booking i've tried to do everything i've stopped the while loop, did the LIMIT 1 option , ordered the results by booking_reference ASC and DESC everything and nothing is changing any help ? thanks for your time [1][edited by: coopster at 3:35 pm (utc) on Dec. 5, 2009]
global $connection;
if(isset($id) && isset($day) && isset($month) && isset($year)){
$query = "SELECT * From room_records ";
$query .= "where room_number = {$id}";
$result_set = mysql_query($query, $connection);
confirm_query($result_set); // this is just to confirm the query
while($result = mysql_fetch_array($result_set)){
$arr_date = "{$result['arr_year']}-{$result['arr_month']}-{$result['arr_date']}";
$dep_date = "{$result['dep_year']}-{$result['dep_month']}-{$result['dep_date']}";
$today = "{$year}-{$month}-{$day}";
$date_arr_explode = explode("-",$arr_date);
$date_dep_explode = explode("-",$dep_date);
$today_explode = explode("-",$today);
$arr_day = mktime(0,0,0,$date_arr_explode,$date_arr_explode[2],$date_arr_explode[0]);
$dep_day = mktime(0,0,0,$date_dep_explode[1],$date_dep_explode[2],$date_dep_explode[0]);
$today = mktime(0,0,0,$today_explode[1],$today_explode[2],$today_explode[0]);
if($today == $arr_day){
$output = "<p class=\"orange\">{$result['room_number']} - {$result['customer_name']}</p>";
}elseif($today > $arr_day && $today < $dep_day){
$output = "<p class=\"orange\">{$result['room_number']} - {$result['customer_name']}</p>";
}else{
$output = "<p class=\"green\">{$result['room_number']} - Available";
}
}
return $output;
}else{
return NULL;
}
}
day is the day in which the cell is within
month is the month of the year submitted to the page
year is the year submitted to the page
second booking 5/12/2009
cell 1/12/2009 the function would be <?php echo getbooking(101,1,12,2009); ?>
[edit reason] removed specifics [/edit]