Mysql query on join

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),

Answers


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

Need Your Help

using C function from other package in Rcpp

c++ c r rcpp

I'm trying to call a C routine from the cubature package in a c++ function to perform multidimensional integration.

Jquery Change background colour on Nav link mouseover

javascript jquery css background mouseover

I want to change the color of background when I hover on different links in my nav menu. Say, link one.. the background goes to red, nav 2 the background goes to blue, nav 3 the background goes to ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.