0
新OOP的。PHP OOP查詢返回空白或陣
試圖在數據庫中查詢特定行。 數據庫的結構爲: ID - 標題 - 價值
(我想查詢比賽冠軍,並獲得後續值)
在陣列或者僅僅是空白的查詢結果兩種。
一些我的格式被混淆或不正確的地方。任何人都可以發現我做錯了什麼嗎?
查詢(這其中,這是被稱爲來自同一個模型內)目錄/模型/ order.php:
public function getTemplate($title) {
$query = $this->db->query("SELECT * FROM km_mail_templates WHERE `title` = '" . $this->db->escape($title) . "'");
foreach ($query->rows as $result) {
$template_data[$result['title']] = $result['value'];
}
return $template_data;
}
變量我試圖撥打:
public function index() {//called from within order.php model
$this->getTemplate()['new_greeting'];
}
而且嘗試過:
$this->model_catalog_order->getTemplate()['new_greeting'];
and
$this->model_catalog_order->getTemplate('new_greeting');
謝謝!我修改了代碼上面,但我還是必須在正確的索引調用它():'PHP致命錯誤:在空in..'而行調用一個成員函數是getTemplate():'$這個 - > model_catalog_order - >是getTemplate()[「new_greeting」]'(我試過其他的變化都是在原來的職位) – necrodeus
如果查詢不返回任何東西,它不會將任何東西放入'$ template_data',所以你是什麼期望從'new_greeting'元素中獲得? – Barmar
另外,你爲什麼不給'getTemplate()'的參數?它期望標題作爲參數進行搜索。 – Barmar