我有2个表格。第一个包含一些全局信息,第二个包含图像列表。MySQL:加入一个多行数据表
当我执行这个请求:
SELECT table1.title, table1.description, table2.image LEFT JOIN table2 ON table2.table1_id = table1.table1_id
表结构:
TABLE1
| table1_id | title | description |
| 1 | title1 | description1 |
| 2 | title2 | description2 |
| 3 | title3 | description3 |
TABLE2
| id | table1_id | image |
| 1 | 1 | img/img1.png |
| 2 | 1 | img/img2.png |
| 3 | 1 | img/img3.png |
| 4 | 2 | img/img4.png |
| 5 | 2 | img/img5.png |
| 6 | 3 | img/img6.png |
我有类似的东西:
<?php
array(
array('title' => 'title1', 'description' => 'description1', 'image' => 'img/img1.png'),
array('title' => 'title1', 'description' => 'description1', 'image' => 'img/img2.png'),
array('title' => 'title1', 'description' => 'description1', 'image' => 'img/img3.png'),
array('title' => 'title2', 'description' => 'description2', 'image' => 'img/img4.png'),
array('title' => 'title2', 'description' => 'description2', 'image' => 'img/img5.png'),
array('title' => 'title3', 'description' => 'description3', 'image' => 'img/img6.png')
);
?>
这种结构的问题是重复标题,说明。 我想获得类似的东西:
<?php
array(
array('title' => 'title1', 'description' => 'description1', 'image' =>
array('img/img1.png', 'img/img2.png', 'img/img3.png')
),
array('title' => 'title2', 'description' => 'description2', 'image' =>
array('img/img1.png', 'img/img2.png')
),
array('title' => 'title3', 'description' => 'description3', 'image' =>
array('img/img6.png')
)
);
?>
我的问题是:
是否有可能得到这样的数据结构只是一个SQL请求(没有PHP操纵。 )
如果不是,我必须做什么样的PHP操作来将我的第一个数组转换为第二个数组?
谢谢!
这个问题有点混乱。也许如果你包含你的相关数据库表结构,这些结构可以帮助我[也许还有其他人]理解潜在的问题。 –
我添加了表格结构 – alexmngn