我想問一些關於查詢.. 我有一個MySQL表,並要產生一點點複雜的表格..查詢mysql的複雜
可以說我有這3個表..
Ship_terms
id | Name | Keterangan
-------------------------
1 | Installation | Instalasi
2 | Delivery | Pengiriman
Shipp_list
id | tipeShipp | namaShipp | Keterangan
----------------------------------------
1 | 1 | KMA | Bla Bla Bla
2 | 1 | MTECH | Bla Bla Bla
3 | 2 | JNE | Bli Bli BLi
Shipp_price
id | idShipp | kota | price
_______________________________
1 | 1 | Jakarta | 0
2 | 2 | Jakarta | 0
3 | 3 | Bandung | 10000
4 | 3 | Jakarta | 5000
注: ship_terms.id = shipp_list.tipeShipp,shipp_price.idShipp = shipp_list.id
,什麼我真正想要的.. 查詢的結果(使用「哥打=雅加達')是這樣的...
-----------------
INSTALLATION
-----------------
1. KMA - 0
2. MTECH - 0
-----------------
DELIVERY
-----------------
1. JNE - 5000
這裏的任何人都可以幫助我? 感謝
* UPDATE
這裏是我的查詢:
{
/* Jika tersedia, lakukan pengambilan data */
/* Hitung berat */
$queryBerat = "SELECT SUM(berat)as berat FROM tmp_detail_jual WHERE username = '$_SESSION[uname]'";
$run = $db->query($queryBerat);
$data_berat = $run->fetch(PDO::FETCH_ASSOC);
$berat = $data_berat[berat]*$data_berat[jumBarang];
$beratTot = ceil($berat);
/* ambil data shipping */
while($data_table = $cek->fetch(PDO::FETCH_ASSOC)){
$idShipp = $data_table[idShipp];
$harga = $data_table[price];
/* ambil nama kurir */
$querynama = "SELECT * FROM shipp_list where id='$idShipp'";
$getNama = $db->query($querynama);
while($namaShipp = $getNama->fetch(PDO::FETCH_ASSOC)){
$nama = $namaShipp[namaShipp];
$keterangan = $namaShipp[keterangan];
$tipeShipp = $namaShipp[tipeShipp];
$idShippList = $namaShipp[id];
/* Cek tipe kurir */
$queryjenis = "SELECT * FROM ship_terms where id='$tipeShipp'";
$getJenis = $db->query($queryjenis);
while($namaTerms = $getJenis->fetch(PDO::FETCH_ASSOC)){
$namaTerm = $namaTerms[name];
$keterangan = $namaTerms[keterangan];
/* Echo datanya */
echo '<br>'.$namaTerm.'<br>';
echo $nama.' - '.$harga*$beratTot;
}
}
}
}
但我得到的結果是這樣
-----------------
INSTALLATION
-----------------
KMA - 0
-----------------
INSTALLATION
-----------------
MTECH - 0
-----------------
DELIVERY
-----------------
JNE - 5000
你可以給一個建議,所以我的查詢結果像這樣
-----------------
INSTALLATION
-----------------
1. KMA - 0
2. MTECH - 0
-----------------
DELIVERY
-----------------
1. JNE - 5000
問題不明確 – user1972007
看起來像英文,不... ? –