Note that there are some explanatory texts on larger screens.

plurals
  1. PO4 mysql table joins?
    text
    copied!<p>I have a complicated query (I think) and whether there is a better way of going about this, because clearly this is not working. </p> <p>I have 4 tables and somehow need to join them. I need to get the red_value, blue_value, and green values from one table where the id of another table = {some number} and the layer = {some number}.</p> <p>Here are the tables:</p> <pre><code>product_color: **color_id (primary)** red_value green_value blue_value set_color: **setcolors_id(primary)** **school_art_id (school_art -primary key)** **baseimage_id (baseimage - primary key)** **color_id (product_color - primary key)** layer (same number value as the layer in the "baseimage"table) baseimage: **id (primary key)** layer (same value as layer in "set_color") school_art: **id (primary key)** </code></pre> <p>Here is the code:</p> <pre><code>public function select_colors($value, $layer) { global $db; $result_array = mysql_query(" SELECT * FROM set_colors INNER JOIN school_art ON set_colors.{$value} = school_art.id INNER JOIN base_product_color ON set_colors.color_id = base_product_color.color_id; INNER JOIN mbaseimage ON set_colors.baseimage_id = baseimage.id WHERE set_colors.{$layer} = baseimage.layer " ); return $result_array; </code></pre> <p>}</p> <p><strong>So what I HOPE to do is to call the class and</strong> </p> <pre><code>get the red_value, green_value and blue_value from the "product_color" table WHERE the "color_id" = the "color_id" of the "set_colors" and "school_art_id" = the {$value} and "layer" = {$layer} </code></pre> <p>Thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload