好吧,我試圖驗證從數據庫訂閱(這似乎工作正常,因爲我在其他地方使用過這種模式)。但是,我試圖拿回返$數據,並在我的看法中使用它作爲IF聲明...但我試圖「如果」沒有出現的DIV。也不會出現任何錯誤。如果我刪除視圖中DIV周圍的IF,內容將會出現......我做錯了什麼?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 ?>
如果你做<? var_dump($ subscription)?>在你的視圖中 - 你會看到變量包含的內容。我敢打賭,它不是「免費贈品」。 – Laurence
'$ query-> result_array();'返回一個數組,你正在檢查'Freebie',這是問題所在。 –
這裏是var dump:'array(1){[0] => array(1){[「subscription」] => string(7)「Freebie」}}' –