dqlb38410 2012-10-26 18:29
浏览 95

从php获取sqlite pdo join查询中的数组

I would like to get a multidimensional array from my sqlite tables, with join. I have two tables:


TABLES:

- projects -----------        - images ------------------
- id                 -        - id                      -
- title              -        - filename                -
- images (has many)  -        - project_id (belongs to) -
----------------------        ---------------------------

and I want the following array


PROJECT_ARRAY
{
   id:     1
   title:  My Project
   images: IMAGES_ARRAY
   {
        image1.jpg
        image2.jpg
        image3.jpg
   }
}

how do I join my tables with sql query?

this does not work:


SELECT   project.title,        image.filename
FROM     project JOIN image
ON       image.project_id = project.id;

  • 写回答

1条回答 默认 最新

  • dongzhuo5425 2012-10-26 18:46
    关注

    You cannot get a array with a subarray from one query.

    Furthermore, your table names are plural, but your are not using the plural names in your query.

    This query should get you going:

    SELECT   p.id, p.title, i.filename
    FROM     projects p 
    JOIN     images i ON i.project_id = p.id;
    

    This should get you a result set like this:

    id: 1, title: My Project, filename: image1.jpg
    id: 1, title: My Project, filename: image2.jpg
    id: 1, title: My Project, filename: image3.jpg
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器