我有一個複雜的查詢(我認爲)以及是否有更好的方法來解決這個問題,因爲顯然這不起作用。4 mysql表連接?
我有4個表,不知何故需要加入他們。我需要從一個表中獲取red_value,blue_value和green值,其中另一個表的ID = {某個數字}和圖層= {某個數字}。
下面是表:
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)**
下面是代碼:
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;
}
所以我希望做的是調用類和
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}
預先感謝您。
那麼究竟是什麼問題呢? 它不會產生正確的結果嗎?它太慢了嗎? – andsens
沒有得到任何結果。沒有錯誤。但沒有結果 – GGcupie
你傳遞給函數的'$ value'和'$ layer'的值是什麼? – Hammerite