The loop does not record the correct values

I have a table containing all the employees in the company (hr_employees). In addition to this table, there is another table with all start and end dates, as well as the type of contract (hr_employees_status).

With the data that I receive, I write 1 or 0 (1 persistent, 0 different) to an Excel spreadsheet, with color coding determined by the type of contract (1 = black, 0 = blue, green, gray or red), every month (with May 2005 to the present). How do I determine what should do, in which cell there is a case argument, looking at the current status in the hr_employee_status table.

It works great and does 99% of what it should do right. The only problem is that, as soon as an employee moves from a temporary contract to a permanent basis, he sometimes does not write the correct value in the cell.

I changed the code a bit to pull only the month and year from the database (and set the day to 01), in the hope that since the month and year is all that is needed to write to the cell, it will write the correct data to the correct cell . But to no avail.

I don't know what code to send, so here is a loop that determines the type of contract and writes it to the excel sheet:

switch ($dates['status']) {
case '0':
    $color = 'blue';
    $cellcontent="0";
    break;
case '1':
    $color = 23;
    $cellcontent="0";
    break;
case '2':
    $color = 'black';
    $cellcontent="1";
    break;
case '3':
    $color = 'green';
    $cellcontent="0";
    break;
case '4':
    $color = 'red';
    if(mysql_num_rows($query) > 2)
        $cellcontent = "0";
    else {
        $cellcontent="1";
    }
    break;
}
if($s['state'] == '4')
    $color = 'red';
$format_content =& $workbook->addFormat(array('align' => 'center', 'size' => 11, 'numformat' => '@', 'fontfamily' => 'Calibri', 'left' => 1, 'bottom' => 1, 'right' => 1, 'color' => $color));
for($f = $start_at; $f <= $start_at+$count; $f++) {
    $totalmonths = $totalmonths + $cellcontent;
    $worksheet->write($k,15+$f,$cellcontent,$format_content);
}

$date - , . $start_at - (, , , ). $count - ( ).

, .

- , .

1: - DaveRandom Oleg

@DaveRandom: hr_employees :

------------------------------------------
|employee_id|name|surname|otherinfo|state|
|1          |Foo |Bar    | ******* |  1  |
|2          |Ben |Smith  | ******* |  1  |
------------------------------------------

hr_employees_status :

------------------------------------------
|employee_id|from_date |to_date   |status|
|1          |2006-07-12|2009-08-11|  0   |
|1          |2009-08-12|0000-00-00|  1   |
|2          |2009-07-01|0000-00-00|  1   |
------------------------------------------

excel

Name      Surname     Start Date     *dates*  June-06  July06  ->- July09 Aug09 Sep09
Foo       Bar         2006-07-12              *empty*     0    ->-   0      1     1
Ben       Smith       2009-07-01              *empty*  *empty* ->-   1      1     1

@Oleg

  • $start_at :

    round(((substr($dates['from_date'],0,4) * 12) + substr($dates['from_date'],5,2)) - ((substr($start_date,0,4) * 12) + substr($start_date,5,2))) + 1;
    // $dates is a loop through the hr_employee_status table
    
  • . . $dates hr_employee_status. 100% , .

  • , ? - varchar ( , , , , ...)

+3
1

- , ( , $start_at ?) ...

  • : " ", , $start_at . .
  • switch ing $dates['status']? , $dates?
  • switch ...

php.net:

switch ("a") {
case 0:
    echo "0";
    break;
case "a": // never reached because "a" is already matched with 0
    echo "a";
    break;
}

, 1 switch statement - $dates['status'], case '0':.

var_dump() , .

0

All Articles