警告:join() [function.join]:传递的参数无效(PHP/MySQL 查询) [英] Warning: join() [function.join]: Invalid arguments passed (PHP/MySQL Query)

查看:47
本文介绍了警告:join() [function.join]:传递的参数无效(PHP/MySQL 查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我我的代码有什么问题?我在最后一行收到错误消息警告:join() [function.join]:传入的参数无效..." - echo join( $URL, '
' );

Can anyone tell me what's wrong with my code? I get the error message "Warning: join() [function.join]: Invalid arguments passed in..." on the very last line - echo join( $URL, '
' );

我检查了这个讨论这个,但没有点击.我将我的查询粘贴到 phpMyAdmin > SQL 中,它工作得很好,返回一个包含两列的表,其中列出了字段 URL 中的值,这些值具有多个实例以及实例数(例如 Bill_Gates | 4).

I checked this discussion and this one, but nothing clicks. I pasted my query into phpMyAdmin > SQL, and it works perfectly, returning a table with two columns listing values in the field URL that have multiple instances along with the number of instances (e.g. Bill_Gates | 4).

所以看起来我的代码肯定有问题 - 除非食物链更高的文件中存在错误,但我认为这不太可能.

So it looks like there must be a problem with my code - unless there's a bug in a file higher up the food chain, but I don't think that's likely.

$stm = $pdo->prepare("select URL, count(*)
from ((SELECT 'GZ' AS GSiteID, NULL as Site, 'Life' AS GSection, GZL.Taxon AS URL
       FROM gz_life GZL WHERE GZL.Taxon = :MyURL
      ) UNION ALL
      (SELECT 'All' AS GSiteID, NULL as Site, 'World' AS GSection, GG.Name AS URL
       FROM gw_geog GG WHERE GG.Name = :MyURL
      ) UNION ALL
      (SELECT 'PX' AS GSiteID, Site, 'People' AS GSection, Ppl.URL
       FROM people Ppl WHERE Ppl.URL = :MyURL
      )
     ) t
group by URL
having count(*) > 1;");
 $stm->execute(array(
 'MyURL'=>$MyURL
 ));

while ($row = $stm->fetch())
{
 $URL = $row['URL'];
}

echo join( $URL, '<br>' );

附言我发布了 var_dump($URL);在上述脚本的最后,但它只显示 string(9) "Zachaenus",这对我来说没有任何意义.(我认为 Zachaenus 是 Life 表中的一个学名.)但我之前从未使用过 var_dump,所以可能我没有正确使用.

P.S. I posted var_dump($URL); at the very end of the above script, but it only displays string(9) "Zachaenus", which doesn't make any sense to me. (I think Zachaenus is a scientific name from the table Life.) But I've never used var_dump before so maybe I'm not doing it correctly.

推荐答案

需要先使用glue参数.

You need to make use of the glue parameter first.

echo join( '<br>',$URL );
           ^^^^^  ^^^^   //<---- Order Interchanged 

或者,您可以使用 implode 与连接相同.

Alternatively, you could make use of implode which does the same of the join.

其次...$URL 必须是数组.

Secondly.. the $URL must be array.

$URL = array();
while ($row = $stm->fetch())
{
 array_push($URL,$row['URL']);
}

这篇关于警告:join() [function.join]:传递的参数无效(PHP/MySQL 查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆