php – 内连接数组结果

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 内连接数组结果脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
查看此数组,可以看到只有foo6值与每个父键不同:

Array
(
    [0] => Array
        (
          [foo1] => Apple
          [foo2] => Banana
          [foo3] => Carrots
          [foo4] => Deer
          [foo5] => Feather
          [foo6] => GraPEs
        )
    [1] => Array
        (
          [foo1] => Apple
          [foo2] => Banana
          [foo3] => Carrots
          [foo4] => Deer
          [foo5] => Feather
          [foo6] => Heater
        )
    [2] => Array
        (
          [foo1] => Apple
          [foo2] => Banana
          [foo3] => Carrots
          [foo4] => Deer
          [foo5] => Feather
          [foo6] => Quail Eggs
        )
)

查询

SELECT
  tpp.page_master_PRoperties_style AS foo1,tpp.page_master_properties_bg AS foo2,tpp.page_master_properties_data AS foo3,tpp.page_properties_style AS foo4,tpp.page_properties_bg AS foo5,tpp.page_properties_data AS foo6,tobj.objects_script AS foo6
From templates t
  INNER JOIN category tc
    ON t.category_id = tc.category_id
  INNER JOIN page_properties tpp
    ON t.templates_id = tpp.templates_id
  INNER JOIN objects tobj
    ON t.templates_id = tobj.templates_id
WHERE
  t.templates_id = ?

哪里? = 1

这可能是因为Table对象有多个templates_id条目:

+--------------+----------------+-----------------+
|  objects_id  |  templates_id  |  objects_script |
+--------------+----------------+-----------------+
|       1      |        1       |      Grapes     |
|       2      |        1       |      Heater     |
|       3      |        1       |     Quail Eggs  |
|       4      |        2       |       Milk      |
|       5      |        3       |       Lemon     |
+--------------+----------------+-----------------+

我想知道是否有任何内置的MysqL函数可以将foo6组合成一个奇异的数组,例如实现这样的结果:

Array
(
  [foo1] => Apple
  [foo2] => Banana
  [foo3] => Carrots
  [foo4] => Deer
  [foo5] => Feather
  [foo6] => Array
            (
              [0] => Grapes
              [1] => Heater
              [2] => Quail Eggs
            )
)

解决方法

这看起来像是MysqL arsenal中的 group_concat作业:

SELECT
  tpp.page_master_properties_style AS foo1,group_concat(tpp.page_properties_data) AS foo6,tobj.objects_script AS foo6
From templates t
  INNER JOIN category tc
    ON t.category_id = tc.category_id
  INNER JOIN page_properties tpp
    ON t.templates_id = tpp.templates_id
  INNER JOIN objects tobj
    ON t.templates_id = tobj.templates_id
WHERE
  t.templates_id = ?
group by
  tpp.page_master_properties_style AS foo1,tpp.page_properties_bg AS foo5

这会将tpp.page_properties_data中的所有行组合到唯一的数据行中并用逗号分隔 – 当您循环遍历数据集时,可以轻松地将explode分成数组.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 内连接数组结果全部内容,希望文章能够帮你解决php – 内连接数组结果所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。