Reputation: 97
This might seem simple but is not correctly working. The if statement looks correct. I am basically saying that if there is data in the table show everything in brackets otherwise do not show at all. In psuedo code I am doing this:
if (query > = 1) {
//show foreach loop and clear form button
} else {
//do not show anything
}
In real markup I have tried this:
<?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
}
?>
Update:
Variable user_promos is the variable set to the query. The query in the dropdown_add_promos method is returned as an array.
$data['user_promos'] = $this->model_location->dropdown_add_promos($fkUserId);
Upvotes: 0
Views: 61
Reputation: 653
if(!empty($data['user_promos']))
{
// check
if(count($data['user_promos']) > 0)
{
//do something
}
else{
// don't do anything
}
}
else
{
// error message
}
You should try above condition.
Inner condition is used only if you want to count the data otherwise outer condition is enough to check data is coming or not.
Upvotes: 0
Reputation: 494
you are setting $data['user_promos'] but you are checking on $user_promos... that may be the issue.
do you get anything from that
<?php
if($user_promos){
//print_r($user_promos);
?>
?
Upvotes: 0
Reputation: 3520
Try count()
since its an array
it will give you count of number of items in array
if(count($user_promos) >= 1)
...
Upvotes: 1