我得到了2個表,table1 & table2。SQL查詢,我需要一些值
table1的字段有:
id
atype
adesc
aid
表2字段有:
id
aid
adesc
value_1
value_2
$query1 = mysql_query("Select DISTINCT atype from table1");
while($row = mysql_fetch_array($query1)){
$atype = $row['atype'];
$query2 = mysql_query("Select adesc from table1 where atype='$atype' and aid IN (Select aid from table2) order by id asc");
while($row2 = mysql_fetch_array($query2)){
// i know query2 can only get adesc, so i need value_1 and value_2 in this
echo $row2['adesc'] .'>> '. (this should be value1 from table2) .'>> '. (this should be value2 from table2);
}
}
我想要得到的value_1
和value_2
。任何幫助,將不勝感激。
編輯:
table1的值是在我的數據庫(atype的,援助,adesc分別):在我的表2
type1 111 'this is type 1'
type1 111 'this is type 1'
type2 112 'this is type 2'
type3 113 'this is type 3'
type4 114 'this is type 4'
type1 111 'this is type 1'
type4 114 'this is type 4'
type2 112 'this is type 2'
值(援助,adesc,VAL1, val2,分別):
111 'this is type 1' 100 50
111 'this is type 1' 100 50
112 'this is type 2' 300 500
113 'this is type 3' 100 50
112 'this is type 2' 100 50
114 'this is type 4' 100 50
111 'this is type 1' 100 50
我在說什麼盟友希望工程是這樣的:
type1
(sum)value_1 (sum)value_2
type2
(sum)value_1 (sum)value_2
type3
(sum)value_1 (sum)value_2
type4
(sum)value_1 (sum)value_2
我真的希望'$ atype'是從不使用 「翡翠的類型」'。 – tadman