这可能看似简单但不正确。 if语句看起来正确。我基本上是说,如果表中有数据显示括号中的所有内容,否则根本不显示。 在psuedo代码中我这样做:
if (query > = 1) {
//show foreach loop and clear form button
} else {
//do not show anything
}
在实际标记中,我试过这个:
<?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
}
?>
更新
变量user_promos是设置给查询的变量。 dropdown_add_promos方法中的查询作为数组返回。
$data['user_promos'] = $this->model_location->dropdown_add_promos($fkUserId);
答案 0 :(得分:1)
尝试count()
,因为array
它将为您提供数组中项目数的计数
if(count($user_promos) >= 1)
...
答案 1 :(得分:0)
您正在设置$ data [&#39; user_promos&#39;],但您正在检查$ user_promos ...这可能是问题。
你从中获得了什么
<?php
if($user_promos){
//print_r($user_promos);
?>
答案 2 :(得分:0)
if(!empty($data['user_promos']))
{
// check
if(count($data['user_promos']) > 0)
{
//do something
}
else{
// don't do anything
}
}
else
{
// error message
}
你应该尝试以上条件。
内部条件仅在您想要计算数据时使用,否则外部条件足以检查数据是否到来。