Berlian
Berlian

Reputation: 55

How to show table from value in dropdown? codeigniter

I have a dropdown like this:

<form action="" method="post">
    Pilih Manajemen asset yang akan ditampilkan :
    <select name="laporan">
        <option value="">Manajemen Aset</option>
        <option value="panel">Laporan Penel</option>
        <option value="lampu">Laporan Lampu</option>
    </select>
    <input class="command-button primary" type="submit" name="tampilkan" value="Tampilkan">
</form>

What I want is: If I chose value "panel" from the dropdown and I clicked the button (name="tampilkan"), it will show table. And if I choose value "lampu", it will show different table.

I tried with this code :

<?php
if(isset($_POST['tampilkan'])) {
    if(isset($_POST['laporan'])== 'panel') {
?>
       //will shown table 1


     <?php
    }

    else if(isset($_POST['laporan'])== 'lampu') {
        ?>

        //will shown table 2
    <?php
    }

}
?>

But it doesn't work. I really need your help, thanks.

Upvotes: 0

Views: 475

Answers (2)

RJParikh
RJParikh

Reputation: 4166

Concept is to check isset only once.

<?php
    if(isset($_POST['tampilkan'])) {
        if($_POST['laporan']== 'panel') {
    ?>
           //will shown table 1


         <?php
        }

        else if($_POST['laporan'] == 'lampu') {
            ?>

            //will shown table 2
        <?php
        }

    }
    ?>

OR

if(isset($_POST['tampilkan']) && $_POST['laporan']== 'panel') {
           // Show table 1
 }
elseif(isset($_POST['tampilkan']) && $_POST['laporan']== 'lampu') {
           // Show table 2
 }

Upvotes: 0

Mr. Engineer
Mr. Engineer

Reputation: 3515

You have problem with your if condition. Try this condition :

if(isset($_POST['laporan']) && $_POST['laporan'] == 'panel') {
    echo "TAB1";
}

Upvotes: 1

Related Questions