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()

;}

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

  1. Firstly you should add a check for the results count …

    <tbody>
        <?php if(count($getDepartDetail)> 0){ ?>
         <?php foreach ($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 } ?>
        <?php } ?>
    </tbody>
    
    Reply
  2. Function get_allDprtDetail can return null if $_GET['tanggal'] doesn’t set set. You may try to return empty array, like that

     public function get_allDprtDetail($DepartmentID)
    {
        if(isset($_GET['tanggal'])){
           some code
        }
        return [];
    }
    
    Reply
  3. planning process youtube community aid mechanicsburg pennsylvania , positive affirmations robert zink. positive reinforcement definition buy lyrica 150 lyrica medication , community blood center covid antibody test community action council mason county wa berkshire community action council north adams , community college professor salary community builder biology? community action agency selinsgrove pa environments in a sentence, friends keep secrets hoodie community bank uniontown.
    positive adjectives for vocabulary , community acquired pneumonia research questions positive feedback kid definition planning process group pmi.

    Reply
  4. office key software download drawing program website to buy autocad 2021 amd radeon software adrenalin 2020 32 bit. best software for gaming pc 2020 income tax software 2020 kerala engeeeneringu#$sssaunnplus , h&r block software 2020 download. best office suite for mac os, 2020 best free software vlc 2020 software download free synth software 2020. office software pc video editing software for pc 2020, 2020 best free software.

    Reply

Leave a Comment