I cant runs the second condition and failed to get datas ['tanggal']

I have code to filter by dates, I have 2 condition,

  1. First condition: get ‘tanggal’ from date picker on view
  2. Second condition: variable ‘tanggal’ isNull

However, the code only runs the second condition, even though the condition variable date is given

This is the code:

View:

.... some code ....
   <form method="POST">
        <div class="form-group">
            <label>Date</label>
            <div class="input-group date">
                <div class="input-group-addon">
                    <span class="glyphicon glyphicon-th"></span>
                </div>

                <form method="get">
                    <input type="date" name="tanggal">
                    <input type="submit" value="FILTER">
                </form>

.... some code ....

                <tbody>
                    <?php
                    foreach ((array)$getDepartDetail as $us) { ?>
                        <tr>
                            <td><?php echo $us->Name ?></td>
                            <td><?php echo $us->NIK ?></td>
                            <td><?php echo $us->gender ?></td>
                            <td><?php echo $us->PositionDesc ?></td>
                            <td><?php echo $us->Shift ?></td>
                            <td><?php echo $us->tgl ?></td>
                            <td><?php echo $us->Attendance ?></td>
                            <td><a class="btn btn-info" href="<?php echo site_url('data_detail/detail_datas/vieworc/' . $us->NIK); ?>">Detail</a></td>
                        </tr>
                    <?php } ?>
                </tbody>

.... some code ....

Model:

.... some code ....
    public function get_allDprtDetail($DepartmentID)
        {
            if(isset($_GET['tanggal'])){
                $tgl = $_GET['tanggal'];
    
            $datas = "
            SELECT DISTINCT
            .... some code ....
        FROM
            emp0001
            INNER JOIN emp0003 ON emp0003.DepartmentID = emp0001.DepartmentID
            LEFT JOIN v_dvc0004_test ON emp0003.NIK = v_dvc0004_test.NIK 
                    AND DATE(v_dvc0004_test.Enroll) = '$tgl'
            JOIN emp0002 ON emp0002.PositionID = emp0003.PositionID
            LEFT JOIN shift ON emp0003.Shift_ID = shift.Shift_ID 
        WHERE
            emp0001.DepartmentID = '$DepartmentID' 
            AND emp0003.IsActive = 'T' 
        ORDER BY
            v_dvc0004_test.Enroll ASC
        
        ";}
            else{
                $datas = "
                SELECT DISTINCT
                .... some code ....
            }
                $query = $this->db->query($datas);
                return $query->result()

;}

18 thoughts on “I cant runs the second condition and failed to get datas ['tanggal']”

Leave a Comment