我想要的行獲取數據庫表的Forch的它呼應一個,但有以下錯誤:錯誤:()提供的foreach無效參數
$query = $this -> db -> query('
SELECT
@rownum := @rownum + 1 rownum,
tour_foreign.id,
tour_foreign.name,
MIN(tour_foreign_residence.name_re) AS name_re,
tour_foreign.service,
tour_foreign.date_go,
tour_foreign.date_back,
tour_foreign.term,
tour_foreign.useradmin_submit,
tour_foreign.date_submit,
GROUP_CONCAT(tour_foreign_residence.name_re
ORDER BY tour_foreign_residence.name_re
SEPARATOR " "
) AS name_re_all
FROM tour_foreign
INNER JOIN tour_foreign_residence
ON (tour_foreign.id = tour_foreign_residence.relation)
JOIN (SELECT @rownum := 0) r
WHERE tour_foreign.name LIKE "%' . $find . '%"
OR tour_foreign_residence.name_re LIKE "%' . $find . '%"
GROUP BY tour_foreign.id ');
foreach ($query->result() as $row) {
echo $row->name_re_all //thisoutput is: 11111 22222 33333 44444 ...
foreach ($row->name_re_all as $val) {
echo $val . '<br>';
}
}
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: core/Loader.php(679) : eval()'d code
Line Number: 86
哪條foreach語句是第86行?如果是後者,請嘗試在foreach循環之前使用explode($ row-> name_re_all,'') – Belinda
此行:'foreach($ row-> name_re_all as $ val){' –