Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php if语句执行不正确_Php_Codeigniter - Fatal编程技术网

Php if语句执行不正确

Php if语句执行不正确,php,codeigniter,Php,Codeigniter,这可能看起来很简单,但并不正确。if语句看起来是正确的。我基本上是说,如果表格中有数据,请在括号中显示所有内容,否则根本不显示。 在psuedo代码中,我正在执行以下操作: if (query > = 1) { //show foreach loop and clear form button } else { //do not show anything } 在real markup中,我尝试了以下方法: <?php if($user_promos >= 1) {

这可能看起来很简单,但并不正确。if语句看起来是正确的。我基本上是说,如果表格中有数据,请在括号中显示所有内容,否则根本不显示。 在psuedo代码中,我正在执行以下操作:

if (query > = 1) {

//show foreach loop and clear form button

} else {

//do not show anything

}
在real markup中,我尝试了以下方法:

 <?php if($user_promos >= 1) { ?>

             <?php
            if($user_promos){
                //print_r($user_promos);
            ?>
            <div class="row">
              <div class="col-md-12">
                <h3>Add Event To Location</h3>
                <div class="row">

                  <div class="row">
                  <div class="row">

                    <div id="myselect2" class="col-md-12">
                        <p></p>

                      <div class="form-group col-xs-5 col-lg-3">
                      <?php 
                        //$user_events = '';
                        //print_r($user_events);
                        $ar=array();
                        foreach($user_events as $events) {
                            $ar[$events['id']] = $events['title'];
                            }
                      //endforeach;
                        ?>

                        <?php
                        $attributes = '';
                         //$attributes='';
                         echo form_dropdown('myselect', $ar, '',$attributes);    

                        ?> 

                    </div>
                  </div>
                </div>

              </div>
              </div>
              <?php    
              }
              ?>
              <button id="grab1" type="button" class="btn btn-default">Clear</button>
                      <hr/>
            </div>
             <?php    
              }
              ?>
尝试
count()
,因为它是一个
数组
它将为您提供数组中项目数的计数

if(count($user_promos) >= 1)
...

您正在设置$data['user\u promos'],但正在检查$user\u promos。。。这可能就是问题所在

你从中得到什么了吗

<?php
if($user_promos){
//print_r($user_promos);
?>

?

您应该尝试上述条件。


仅当您要计算数据时才使用内部条件,否则外部条件足以检查数据是否到达。

是$user\u promos是数组还是整数?@Khushboo请参阅我原始帖子底部的更新。
<?php
if($user_promos){
//print_r($user_promos);
?>
if(!empty($data['user_promos']))
{
  // check
  if(count($data['user_promos']) > 0) 
  {
     //do something
  }
  else{
     // don't do anything
  }
}
else
{
// error message
}