0
這是怎麼代碼轉換爲笨代碼:如何將此代碼中的錯誤轉換並修復爲CodeIgniter?
search_hotel: - >這是CI_Model
return mysql_query("select * from hotel_submits where name LIKE '".$searchterm."'")
我嘗試,但有錯誤:
$query = $this->db->order_by("id", "desc")->like('name', '$searchterm')->get('hotel_submits');
return $query->row();
錯誤:
A PHP Error was encountered
Severity: Warning
Message: mysql_fetch_assoc() expects parameter 1 to be resource, array given
Filename: admin/tour.php
Line Number: 15
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: admin/tour.php
Line Number: 21
code: - >這是CI_Controller
$searchterm = $this->input->post('search_hotel');
$result = $this->model_tour->search_hotel($searchterm);
while ($row = mysql_fetch_assoc($result)) { //this is line 15
//giving names to the fields
$data = array (
'name' => $row->name,
);
}
echo json_encode($data); //this is line 21
控制器應該「回顯」數據,而不是「返回」它。 –
好點!相應編輯。 – simnom
'$ this-> model('your_model_name')'無效。它應該是'$ this-> your_model_name'。搜索結果的 –