我想问一些关于查询的问题。我有一个 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
而我真正想要的是..查询的结果(使用'kota = jakarta')是这样的......
-----------------
INSTALLATION
-----------------
1. KMA - 0
2. MTECH - 0
-----------------
DELIVERY
-----------------
1. JNE - 5000
这里有人可以帮助我吗??谢谢
*更新
这是我的查询:
{
/* 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