Reputation: 5367
Okay, I'm trying to verify a subscription from a database (which appears to work fine, as I've used this model elsewhere). However, I'm trying to take the returned $data and use it as an IF Statement in my view...but the DIV I'm trying to "if" is not showing up. Nor do any errors appear. If I remove the IF around the DIV in the view, the content will appear...what am I doing wrong?
Here's the code in my controller:
// 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;
Model:
// 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
}
and finally, my IF statement in the view I'm trying to output:
<? if($subscription == 'Freebie') : ?>
<div>some "freebie" content</div>
<? endif ?>
Upvotes: 1
Views: 76
Reputation: 146219
You can use
if($subscription[0]['subscription'] == 'Freebie')
instead of
if($subscription == 'Freebie')
More about Generating Query Results.
Upvotes: 1