【问题标题】:Integrating For Each Loop and MySql Variable Associative Array为每个循环和 MySql 变量关联数组集成
【发布时间】:2013-01-04 21:34:46
【问题描述】:

以下行是 for each 循环的一部分,该循环遍历从 SQL 查询返回的关联数组。我收到此错误:

可捕获的致命错误:stdClass 类的对象无法转换 串入。

当我为$field2 使用分配变量时会发生错误。但是,如果我将$field2 替换为表中的实际字段名称county_slug,它就可以工作。

如何在下面的语句中使用变量?

 echo "<a href='/dealers/3/$geography->$field2/'>$geography->county_short</a>"

【问题讨论】:

  • {}中的内容括起来为{$geography-&gt;$field2}

标签: mysql arrays variables for-loop


【解决方案1】:

正如迈克尔所说。

使用{} 括起来作为{$geography-&gt;$field2}

但是您的行中存在另一个错误。您缺少结束您的分号来结束您的陈述。 ;

您的线路应如下所示:

echo "&lt;a href='/dealers/3/{$geography-&gt;$field2}/'&gt;$geography-&gt;county_short&lt;/a&gt;";

【讨论】:

  • 我想你的意思是echo "&lt;a href='/dealers/3/{$geography-&gt;$field2}/'&gt;$geography-&gt;county_short&lt;/a&gt;";
  • 谢谢你解决它。语句中的 { 是什么意思?
猜你喜欢
  • 2014-11-24
  • 2014-08-01
  • 2011-01-23
  • 1970-01-01
  • 2014-11-09
  • 2011-12-22
  • 2011-04-01
  • 1970-01-01
  • 2019-03-07
相关资源
最近更新 更多