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

发布于 2024-12-10 11:54:03 字数 1340 浏览 0 评论 0原文

我想要获取数据库表的一行 forch 来回显每个 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() 代码

行号:86

I want for a row that get of database table forch it for echo each a but have following error:

$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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-12-17 11:54:03

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

Foreach is used to iterate trough an array, you're passing a string as a parameter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文