Citra45Abadi Citra45Abadi - 1 year ago 48
MySQL Question

mysqli query select * not returning a certain field

only 1 field is not returned, the rest of it is returned correctly

the problem is I used the same query for other page and it returned everything okay

the problematic PHP :

$sql=mysqli_query($con,"SELECT * FROM produk INNER JOIN kategori ON produk.id_kategori=kategori.id_kategori WHERE id_produk='$_GET[id]'");

echo"judul produk : $r[nama_produk] <br />
nama kategori : $r[nama_kategori]<br />
judul gambar : $r[gambar]";

the results :

judul produk : test mesin kyocera

nama kategori : kyocera

judul gambar :

another php, used on other page which is pretty much the same but works fine :

$sql=mysqli_query($con,"SELECT * FROM produk INNER JOIN kategori2 ON produk.id_kategori2=kategori2.id_kategori2 ORDER BY rand() DESC LIMIT 25");
include "diskon_stok.php";
<div class='container_produk'>
<div class='preview'>
<span style='font-size : 22px'>$r[nama_kategori2]</span>
<span style='font-size : 14px'>$r[preview]</span>
<button class='pre-button'><a href='produk-$r[id_produk]-$r[nama_produk].html'>Detail</a></button>
<img style='margin-left : 5%;' src='foto_produk/small_$r[gambar]'/>
<div class='detail'>
<span style='font-size : 22px'>$r[nama_produk]</span>
<br />
<br />


now the field not returned is $r[gambar] on Code 1, but on Code 2 $r[gambar] is returned and thus the image is showing on browser

so did I do something wrong somewhere?

Answer Source

turns out my query is wrong

it should be written like this

$sql=mysqli_query($con,"SELECT * FROM produk,kategori WHERE produk.id_kategori=kategori.id_kategori AND id_produk='$_GET[id]'");

no need to type INNER JOIN or JOIN

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download