错误:为foreach()提供的参数无效

时间:2011-10-19 11:50:58

标签: php codeigniter

我想要一个获取数据库表的行,用于回显每个a但有以下错误:

$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>';
    }
}
  

遇到PHP错误

     

严重性:警告

     

消息:为foreach()提供的参数无效

     

文件名:core / Loader.php(679):eval()'d code

     

行号:86

1 个答案:

答案 0 :(得分:1)

Foreach用于遍历数组,您将字符串作为参数传递