hey guys...
hope you do not mind, I need some of your help here. I have 'strange' appearance on my table. I am trying to display employee availability calendar.
Below are the code that I have:
<?
/* function to get dates between start and end dates and place them in simple array */
function listdates($startdate,$enddate,$leave_info){
$startdate = strtotime($startdate);
$enddate = strtotime($enddate);
$i = $startdate;
while($i <= $enddate) {
$dates = $dates."--".date("Y-m-d",$i)."-".$leave_info;
$i = $i + 86400;
}
$ardates = split("--",$dates);
return $ardates;
}
$hostname="localhost";
$username="myusername";
$password="mypwds";
$database="mydbname";
$connection = mysql_connect($hostname, $username, $password) or die(mysql_error()."<b>Unable to Connect to the Server");
mysql_select_db($database,$connection) or die(mysql_error()."<b>Unable to Connect to the Database!</b>");
$mysql_emp_list_query = "select employee_id, first_name, last_name from personnel where is_active=1 order by first_name ASC";
$emp_list_result = mysql_query($mysql_emp_list_query);
$emp_id = 0;
$prev_emp_id = $emp_id;
while ($emp_listrow = mysql_fetch_row($emp_list_result))
{
$emp_id = $emp_listrow[0];
if ($emp_id != $prev_emp_id){
$n_days_of_month = date("t", mktime(0,0,0, $month, date(d),$year));
print "<tr>";
print "\t\t<td colspan=5 bgcolor=#FFFFFF><span class=\"empname\">".$emp_listrow[1]." ".$emp_listrow[2]." </span></td>";
for ( $day = 1 ; $day <= $n_days_of_month ; $day ++)
{
$day_of_month = date("Y-m-d", mktime(0,0,0, $month , $day, $year));
$day_of_week = date("w", mktime(0,0,0, $month , $day, $year));
if ($day_of_week != 6 && $day_of_week != 0){
print "<td width=22 align=center bgcolor=#EEEEEE><font face=arial size=1>$day_of_month</font></td>";}
else {
print "<td width=22 align=center bgcolor=#999999><font face=arial size=1>$day_of_month</font></td>";
}
/*** Beginning of 2nd Query to get Info from emp_avail_table ***/
$mysql_event_info_query = "select * from emp_avail_table where employee_id = \"$emp_id\" order by employee_id ASC";
$event_info_result = mysql_query($mysql_event_info_query);
while ($event_info_listrow = mysql_fetch_row($event_info_result))
{
$startend_dates = listdates($event_info_listrow[2],$event_info_listrow[3],$event_info_listrow[4]);
/*** loop through and put the dates from function into array and display to calendar table ***/
for($i = 0; $i <= count($startend_dates);$i++)
{
$exp_date = substr($startend_dates[$i],0, strlen($startend_dates[$i])-4);
$empleave_info = substr($startend_dates[$i], strlen($startend_dates[$i])-3,3);
if ($exp_date != $day_of_month) print"\t\t";
else if ($exp_date = $day_of_month)
print "\t\t<td width=22 align=center bgcolor=#EEEEEE><span class=\"info\">$empleave_info</span></td>";
}/*** End of 'for-i' loop ***/
}/*** End of 2nd Query to get Info from emp_avail_table ***/
}/*** End of 'for-day' loop ***/
$prev_emp_id = $emp_id;
} // end of 'if' to check if $emp_id equals $prev_emp_id to prevent double printing same records
else print "\t\t";
print "</tr>";
}
/*** End of 'while-loop' to get Employee List from Personnel Table ***/
mysql_close();
?>
My problem occurs on the second 'for-loop' (for ($i=0...) {}) I do not know what is wrong with it. When it prints the 'Leave Info', instead of print it right in the respectively '$day_of_month' cell, it prints on the next cell. That cause my table on that specific row to go out of bound.
I believe it has something to do with the 'if-else' statement before the 2nd query. I tried to move it down after the second 'for-loop', the result is the same as before only this time, the 'Leave Info' is printed before the '$day_of_month' cell.
I do not want to delete that particular 'if-else' statement, since it prints out the grids on my calendar. If I delete it, there will be no grid.
I hope you understand what I was trying to say here. If there is someone out there can tell me what's wrong with my code and show me how to make it works, I will really appreciate your help.
Thank you in advance...