IF声明 - 未出现

时间:2012-11-14 02:51:30

标签: codeigniter codeigniter-2

好的,我正在尝试从数据库验证订阅(看起来工作正常,因为我在其他地方使用过此模型)。但是,我正在尝试获取返回的$ data并在我的视图中将其用作IF语句...但是DIV我试图“if”没有出现。也不会出现任何错误。如果我在视图中删除DIV周围的IF,内容将会出现......我做错了什么?

这是我控制器中的代码:

// Check subscription and display appropriate content if "freebie" package 
$subscribe_result = $this -> subscribe_model -> upgrade_message($this->session->userdata('user_id')); // session sends user id to model
$data['subscription'] = $subscribe_result;

型号:

// Checks to see what package user has subscribed to
public function upgrade_message($id) //$id is session id pulled from controller
{
    $this -> db -> select('subscription'); // select the subscription column
    $this -> db -> where('id', $id); //find id in table that matches session id
    $query = $this -> db -> get("subscriptions"); // connect to this database

    return $query->result_array(); //returns the result of the above
}

最后,在我试图输出的视图中我的IF语句:

<? if($subscription == 'Freebie') : ?>
    <div>some "freebie" content</div>
<? endif ?>

1 个答案:

答案 0 :(得分:1)

您可以使用

if($subscription[0]['subscription'] == 'Freebie')

而不是

if($subscription == 'Freebie')

有关Generating Query Results的更多信息。

相关问题