phpmysql

insert one more row in a table if the day is Saturday


I have a table with a monthly report of some groups. I want to add one more row in the table if the day is Saturday.

<tr>
    <td>".$data."</td>
    <td>"."<i>".$totMirela."</i> <b style='color:green'>".$grupi['Mirela']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Mirela']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Mirela']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Mirela']."</b> <u><i>".number_format($rezeMirela, 2)."</i><u></td>
    <td>"."<i>".$totANISA."</i> <b style='color:green'>".$grupi['Anisa']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Anisa']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Anisa']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Anisa']."</b> <u><i>".number_format($rezeANISA, 2)."</i><u></td>
    <td>"."<i>".$totARMAND."</i> <b style='color:green'>".$grupi['Armand']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Armand']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Armand']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Armand']."</b> <u><i>".number_format($rezeARMAND, 2)."</i><u></td>
    <td>"."<i>".$totBLERTA."</i> <b style='color:green'>".$grupi['Blerta']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Blerta']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Blerta']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Blerta']."</b> <u><i>".number_format($rezeBLERTA, 2)."</i><u></td>
    <td>"."<i>".$totDORIS."</i> <b style='color:green'>".$grupi['Doris']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Doris']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Doris']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Doris']."</b> <u><i>".number_format($rezeDORIS, 2)."</i><u></td>
    <td>"."<i>".$totORNELA."</i> <b style='color:green'>".$grupi['Ornela']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Ornela']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Ornela']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Ornela']."</b> <u><i>".number_format($rezeORNELA, 2)."</i><u></td>
    <td>"."<i>".$totXHULJANO."</i> <b style='color:green'>".$grupi['Xhuljano']['kontratat_ok']."</b> <br><b style='color:red;'>".$grupi['Xhuljano']['kontratat_ko']."</b> <b style='color:blue;'>".$grupi['Xhuljano']['kontratat_att']."</b> <br><b style='color:brown'>".$kontratat_ore[$data]['Xhuljano']."</b> <u><i>".number_format($rezeXHULJANO, 2)."</i><u></td>
    <td>"."<i>".$kontratat_tot[$data]['totali']."</i> <b style='color:green'>".$kontratat_tot[$data]['ok']."</b> <br><b style='color:red;'>".$kontratat_tot[$data]['ko']."</b> <b style='color:blue;'>".$kontratat_tot[$data]['att']."</b> <br><b style='color:brown'>".$giorno_ore."</b> <u><i>".number_format($reze_giorno, 2)."</i><u></td>
</tr>";

The $data variable has the date which is in this format ("Y-m-d") or simply 2016-03-09 . Now if the day is Saturday I want to add one more row in this table.

enter image description here

Thank you all!


Solution

  • First You need to check the day.

    Example:

    3 Chars Name of Day
    With 'D' parameter You will get a 3 chars string for the day.

    $timestamp = strtotime('2016-03-10');
    
    $day = date('D', $timestamp);
    var_dump($day);
    
    //Output
    string 'Thu'
    

    Full Name of Day
    With 'l' parameter You will get a full name of day string

    $timestamp = strtotime('2016-03-10');
    
    $day = date('l', $timestamp);
    var_dump($day);
    
    //Output
    string 'Thursday'
    

    Then You need to insert this in your code in a while loop or an if to check the columns.

    This is the function to check the day:

    function DayCheck($inputDate){
       $timestamp = strtotime($inputDate);
       $day = date('l', $timestamp);
       return $day;
    }
    

    And this is how to use in your code:

    if(DayCheck($row['col']) == 'Saturday'){
       //... some code ...
       //... add new row ...
       //... other code ...
    }