2012-11-07 88 views
0

好的,首先请允许我概述我正在尝试做什么。我想在我的视图中显示只显示给某个“订阅”类型的用户的DIV。查找数据库表中的ID并从列中选择值

所以我正在使用用户的会话ID在数据库中查找订阅(订阅以用户ID作为主存储)。一旦发现他们的行与他们的订阅,我想从“订阅”列中获取值。如果值等于“freebie”,我想回显一个语句(我将在这里添加一个函数,一旦我明白了)。

以下是我想到的......我做错了什么?不工作,我没有收到任何错误。

// show appropiate upgrade message if user has free account 

    $id = $this->session->userdata('user_id'); 

    $this->db->select('subscription'); 
    $this -> db -> where('id', '$id'); 
    $query = $this -> db -> get("subscriptions"); 
    $subscribe = $query -> result(); 

    if($subscribe == 'freebie') 
    { 
     echo 'function goes here'; 
    } 

回答

1

请试试这个(我不知道你的列名,这是一个例子)

$id = $this->session->userdata('user_id'); 

$this->db->select('subscription'); 
$this->db->where('id', $id); 
$query = $this->db->get("subscriptions"); 
$subscribe = $query->result_array(); 

if($subscribe[0]['subscription'] == 'freebie') 
{ 
    echo 'function goes here'; 
}else{ 
    echo "No Result"; 
} 
+0

谢谢,但它不工作。错误:致命错误:不能使用类型为stdClass的对象作为数组 –

+0

列名是:id,电子邮件和订阅 –

+0

查看您的编辑。刚刚尝试过,错误消失了。但没有回音。没有错误。 –

相关问题