dqjo4340 2014-06-29 11:24
浏览 21
已采纳

关于连接的Mysql查询

I have two Tables, one is a table of images, the other a table of product ids and image ids.

Medias Table:

`media_id`,  `file_title`,  `file_type`,  `file_url`,

Product-Medias Table:

`id`, `media_id`, 'product_id`

I am trying to get ALL of the matches from the Product-Media Table for a specific product_id.

$query = 'SELECT c.id, pm.file_url FROM `product_medias` c '.
        'INNER JOIN `medias` pm '.
        'ON c.`media_id` = pm.`media_id`'.
        ' AND c.`product_id` = 57 GROUP BY c.id';

The problem I get is I only get one result even if there are multiple images for a product in the product-media table.

ex: Product-Medias Table: I only get the first match in my result...

(47, 57, 65),
(48, 49, 66),
(51, 57, 70),
(52, 57, 71),
  • 写回答

1条回答 默认 最新

  • duanne9313 2014-06-30 00:52
    关注

    Ok I didn't know that:

    $med_rows = mysqli_fetch_array($result, MYSQL_ASSOC);
    

    only returns the first result...

    I needed to loop the result to get all of them:

    while ($med_rows = mysqli_fetch_array($result, MYSQL_ASSOC)) {
            $med_row[] = $med_rows; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序