2
我想將函數get_path()調入select子句(函數get_all_lelang()),但我不知道如何編寫它。你可以幫我嗎?將參數傳遞給select子句Codeigniter
這是我的代碼。
public function get_path($kode_lelang){
$result = $this->db->query("select gambar as gbr from proyek_pertanian NATURAL join lelang where kode_lelang='".$kode_lelang."'")->row_array();
$path = 'http://localhost/sikonsorsium/'.$result['gbr'];
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
return $base64;
}
public function get_all_lelang(){
$sql = "SELECT ".$get_path(."lelang.kode_lelang".)." as binImg, member.*
FROM `lelang`
LEFT JOIN `member` ON `lelang`.`id_member` = `member`.`id_member`
JOIN `proyek_pertanian` ON `lelang`.`kode_proyek` = `proyek_pertanian`.`kode_proyek` ";
$query = $this->db->query($sql);
return $query->result();
}
[編輯]我想這個
public function get_all_lelang(){
$sql = "SELECT '".$this->get_path("lelang.kode_lelang")."' as binImg, member.*
FROM `lelang`
LEFT JOIN `member` ON `lelang`.`id_member` = `member`.`id_member`
JOIN `proyek_pertanian` ON `lelang`.`kode_proyek` = `proyek_pertanian`.`kode_proyek` ";
$query = $this->db->query($sql);
return $query->result();
}
但它返回不同的值,錯誤值。請檢查binImg值。
(錯誤)
"kode_lelang":"LLG-20160616-183314","binImg":"data:image\/;base64,PCFET0NUWVBFIGh0bWw+Cgo8aHRt
(右)
"kode_lelang":"LLG-20160616-183314","binImg":"data:image\/jpg;base64,\/9j\/4AAQSkZJRgABAQAAAQABAAD\/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
請幫助。謝謝:)
哇它的作品!謝謝你:D – Florentina
嘿,我已經意識到它根本不起作用。它返回不同的價值。 我不知道爲什麼。請在控制器中看到我的編輯 – Florentina
它應該工作,您的語法'$ get_path(。「lelang.kode_lelang」。)'不正確,'$ this-> get_path(「lelang.kode_lelang」)'是調用的方式方法裏面的類 –