这是我的代码:
function getPhoto($primary_key , $row){
$this->db->select('id_report, path_photo');
//$this->db->join('report', 'report.id = id_report');
//$this->db->where('id_report', 'id_report');
$this->db->from('report r, photo p');
$where = "p.id_report = r.id AND id_report=".$row->id."";
$this->db->where($where);
$query = $this->db->get()->result_array();
foreach ($query as $row2) {
return " ".$row2['id_report']." - ".$row2['path_photo']."<br>";
//echo " ".$row2['id_report']." - ".$row2['path_photo']."<br>";
}
function admin(){
$crud->callback_column('POTHOS', array($this,'getPhoto'));
.......
我需要从我的数据库中获取我的照片的路径,但报告可以有多张照片,所以我使用return和echo:
(对于这种情况,我有更明确的id和url)
回声:
1 - a.jpeg
1 - b.jpeg
2 - ....
3 - ....
4 - ....
5 - ....
6 - ....
7 - ....
8 - pic1.jpeg
8 - pic2.jpeg
9 - .....
10 - ....
返回:
1 - b.jpeg (Where is the other photo? a.jpeg)
2 - ......
3 - .....
4 - .....
5 - .....
6 - .....
7 - .....
8 - pic2.jpeg (pic1.jpeg?)
9 - .....
10 - .....
答案 0 :(得分:0)
你不能在循环中使用“return”语句......或者循环只运行一次。
相反,在循环内创建一个连接字符串(使用。=)或一个值数组,然后在循环之后返回它:
$myString = '';
foreach ($query as $row2) {
$myString .= " ".$row2['id_report']." - ".$row2['path_photo']."<br>";
}
return $myString;