我想将函数get_path()调用到select子句(函数get_all_lelang()),但我不知道如何编写它。你能帮助我吗?
这是我的代码。
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
请帮忙。谢谢:))
答案 0 :(得分:1)
你需要小幅修正,
更改
$get_path(."lelang.kode_lelang".)
到
$this->get_path("lelang.kode_lelang")