我的“否则”条件不起作用php网站codeigniter

时间:2019-12-12 11:34:19

标签: php html codeigniter web

我的“否则”条件不起作用。

我希望通过某种条件使“ li”类处于活动状态或不处于活动状态,其中数据库表中包含if else语句中的单词的数据是正确的,则“ li”类将处于活动状态。如果“ if else”语句中的单词不在数据库中,则“ li”类将不处于活动状态。

在这种情况下,我从数据库表“ pameran_belanda”中获取“ nama_kegiatan”列,以将值与“ if else”条件相匹配

这是我从表中获取数据的模型:

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

}

这是我的控制器:

 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');

    }

我的观点:

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

输出仅显示“ li”,且类未激活,没有其他条件下我写的单词。

我的表结构有4个数据,我只用2个“ li”来表示我的程序

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

我的全视图

<?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>

我的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");
  });

1 个答案:

答案 0 :(得分:0)

您需要不同地使用foreach

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