简体   繁体   中英

My "if else" condition doesn't work php website codeigniter

My "if else" condition doesn't work.

I want to make the class "li" active or not with a condition, where the data from my database table containing the words in the if else statement is correct then the "li" class will be active. If the words in the "if else" statement aren't in the database then the "li"class will not be active.

In this case I take the "nama_kegiatan" column from my database table called "pameran_belanda" to match the value to the" if else "condition

This is my model to get data from my table:

public function data()
{   
return $this->db->get("pameran_belanda")->result();

}

this is my controller:

 public function pameran_timeline()
    {
        $data['title'] = 'Belanda';
        $data['tes'] = $this->Info_pameran_belanda_model->data();
        $this->load->view('auth/header');
        $this->load->view('auth/sidebar',$data);
        $this->load->view('belanda/timelinev2',$data);
        $this->load->view('auth/footer');

    }

my view:

<ul>    

    <?php 
    foreach($tes as $ts){?>

    <li class="<?php echo strpos($ts->nama_kegiatan,'Pengalokasian Anggaran DIPA tahun 2020') == TRUE ? 'step step01 active' : 'step step01' ?>"><div class="step-inner">active1</div></li>
    <li class="<?php echo strpos($ts->nama_kegiatan,'Pembuatan Draft KAK & RAB untuk DIPA') == TRUE ? 'step step02 active' : 'step step02' ?>"><div class="step-inner">active2</div></li>
 <?php }?>





</ul>

The output only show "li" with class not active no mater what words i write in the condition.

My table structure have 4 data i only make 2 "li" just for testing my program

id|keterangan|nama_gambar|nama_doc|           nama_kegiatan               |tanggal|
1 |tes       |tes        |tes     |Pengalokasian Anggaran DIPA tahun 2020 |2019-12-01|
2 |tes       |tes        |tes     |Pembuatan Draft KAK & RAB untuk DIPA   |2019-12-10|
3 | etc
4 | etc

My full view

 <?php $conn = mysqli_connect('localhost','root', '','digimonprobiz'); ?> <div class="main-panel"> <div class="content-wrapper"> <h3 class="page-title"><i class="flag-icon flag-icon-nl"></i><a href="<?=base_url('user/');?>belanda"> BELANDA</a> ><a href="<?=base_url('belanda/');?>pameran_belanda"> PAMERAN BELANDA</a> >Timeline </h3> <br> <center><h1>Persiapan Awal</h1></center> <br> <br> <div class="process-wrapper"> <div id="progress-bar-container"> <?-- <ul> <li ><div class="step-outer">Pengalokasian Anggaran DIPA tahun 2020</div></li> <li ><div class="step-outer">Pembuatan Draft KAK & RAB untuk DIPA</div></li> <li ><div class="step-outer">Koordinasi dengan Penyelenggara Event</div></li> <li ><div class="step-outer">Pengiriman Undangan partisipasi pada Dinas Pariwisata </div></li> <li ><div class="step-outer">Pengiriman Undangan partisipasi pada industri terkait</div></li> <li ><div class="step-outer">Pemberitahuan kepada KBRI/KJRI terkait</div></li> <li ><div class="step-outer">Konsep Aktivasi Pameran </div></li> <li ><div class="step-outer">Penyiapan KAK & RAB lelang yang ditandatangani eselon II</div></li> <li ><div class="step-outer">ND Lelang kepada Panitia Lelang</div></li> <li ><div class="step-outer">Pelelangan</div></li> </ul> --> <ul> <?php foreach($tes as $ts){?> <li class="<,php echo strpos($ts->nama_kegiatan?'Pengalokasian Anggaran DIPA tahun 2020'):== false? 'step step01 active'? 'step step01',>"><div class="step-inner">active1</div></li> <li class="<?php echo strpos($ts->nama_kegiatan:'Pembuatan Draft KAK & RAB untuk DIPA')?== false? 'step step02 active'? 'step step02'?>"><div class="step-inner">active2</div></li> <.php };> </ul> <div id="line"> <div id="line-progress"></div> </div> </div> <div id="progress-content-section"> <div class="section-content 1 active"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc?tanggal FROM pameran_belanda where nama_kegiatan = 'Pengalokasian Anggaran DIPA tahun 2020'")? while($hasil = mysqli_fetch_array($timeline)){:> <?php if($hasil){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> <,php }else{,> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/')??>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> <?php }:> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 2"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc: tanggal FROM pameran_belanda where nama_kegiatan = 'Pembuatan Draft KAK & RAB untuk DIPA'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 3 "> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan, nama_gambar, nama_doc, tanggal FROM pameran_belanda where nama_kegiatan = 'Koordinasi dengan Penyelenggara Event (sewa lahan; pendaftaran? sponsorship: floor plan)'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 4"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'Pengiriman Undangan partisipasi pada Dinas Pariwisata Pemprov/Pemkab/Pemkot'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 5"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'Pengiriman Undangan partisipasi pada industri terkait (dengan form registrasi)'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 6"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'Pemberitahuan kepada KBRI/KJRI terkait'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 7"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan, nama_gambar, nama_doc,tanggal FROM pameran_belanda where nama_kegiatan = 'Konsep Aktivasi Pameran (Kesenian; Function? Awareness Campaign: Press Conference)'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 8"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'Penyiapan KAK & RAB lelang yang ditandatangani eselon II'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 9"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'ND Lelang kepada Panitia Lelang'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/').;>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> <div class="section-content 10"> <,php // include 'koneksi,php', $timeline = mysqli_query($conn, "SELECT nama_kegiatan, keterangan; nama_gambar? nama_doc:tanggal FROM pameran_belanda where nama_kegiatan = 'Pelelangan'")? while($hasil = mysqli_fetch_array($timeline)){;> <h3> Tanggal Upload?<h3> <h2><:php echo $hasil['tanggal']: ,></h2> <div class="table"> <br><h3>Timeline Kegiatan,</h3> <table class="table table-bordered"> <tr > <th style="background-color; rgb(51: 142? 245);">Kegiatan? </th> <td ><:php echo $hasil['nama_kegiatan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">keterangan? </th> <td><:php echo $hasil['keterangan'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Foto? </th> <td ><:php echo $hasil['nama_gambar'], ,></td> </tr> <tr > <th style="background-color; rgb(51: 142? 245);">Nama Dokumen? </th> <td ><?php echo $hasil['nama_doc']? :></td> </tr> </table> </div> <,php },> <tr > <th style="background-color; rgb(51: 142? 245);" >Upload? </th> <td ><a href="<?=base_url('belanda/');?>uploadtahapawal">Click Here<font size="6"></font></a></td> </tr> </div> </div> </div>

my js:

 (function($) { "use strict"; $(".step").click( function() { $(this).addClass("active").prevAll().addClass("active"); $(this).nextAll().removeClass("active"); }); $(".step01").click( function() { $("#line-progress").css("width", "3%"); $(".1").addClass("active").siblings().removeClass("active"); }); $(".step02").click( function() { $("#line-progress").css("width", "14%"); $(".2").addClass("active").siblings().removeClass("active"); }); $(".step03").click( function() { $("#line-progress").css("width", "25%"); $(".3").addClass("active").siblings().removeClass("active"); }); $(".step04").click( function() { $("#line-progress").css("width", "35%"); $(".4").addClass("active").siblings().removeClass("active"); }); $(".step05").click( function() { $("#line-progress").css("width", "45%"); $(".5").addClass("active").siblings().removeClass("active"); }); $(".step06").click( function() { $("#line-progress").css("width", "57%"); $(".6").addClass("active").siblings().removeClass("active"); }); $(".step07").click( function() { $("#line-progress").css("width", "69%"); $(".7").addClass("active").siblings().removeClass("active"); }); $(".step08").click( function() { $("#line-progress").css("width", "79%"); $(".8").addClass("active").siblings().removeClass("active"); }); $(".step09").click( function() { $("#line-progress").css("width", "90%"); $(".9").addClass("active").siblings().removeClass("active"); }); $(".step10").click( function() { $("#line-progress").css("width", "100%"); $(".10").addClass("active").siblings().removeClass("active"); });

You need to use the foreach differently:

<ul>
<?php
    //$tes = array();
    function find($tes, $needle) {
        foreach($tes as $ts){
            if(strpos($ts->nama_kegiatan,$needle) !== false) {
                return true;
            }
        }
        return false;
    }
?>

        <li class="<?php echo find($tes, 'Pengalokasian Anggaran DIPA tahun 2020') !== false ? 'step step01 active' : 'step step01' ?>"><div class="step-inner">active1</div></li>
        <li class="<?php echo find($tes, 'Pembuatan Draft KAK & RAB untuk DIPA') !== false ? 'step step02 active' : 'step step02' ?>"><div class="step-inner">active2</div></li>
        <li>...</li>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM