0

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
  • 1
    @Rahul Post it as an answer
    – Barmar
    Jun 29, 2014 at 11:28

1 Answer 1

0

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; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.