I'm trying to select all of my column and it works perfectly with this
$query = "SELECT * FROM employee";
$result = mysqli_query($con, $query);
while ($employee = mysqli_fetch_array($result)) {
# code...
print (json_encode($employee));
}
and I also succeed select some of my column using this code
$query = "SELECT ID, NAME, LAT FROM employee";
$result = mysqli_query($con, $query);
but I failed when I try to select LONG column, it said that
mysqli_fetch_array()
expects parameter 1 to bemysqli_result
It just show when I select LONG column, but it works well if I select another column.
"But i failed when i try to select LONG column"
That's because LONG
is a MySQL reserved word.
Either wrap it in backticks, or choose another word for it.
I.e.:
$query = "SELECT ID, NAME, `LONG` FROM employee";
or
$query = "SELECT ID, NAME, LAT, `LONG` FROM employee";
LONG
is a MySQL reserved word. So, your query is resulting in syntax errors when you run mysqli_query()
. To get around that problem, put it in backticks, like this:
$query = "SELECT ID, NAME, LAT, `LONG` FROM employee";
$result = mysqli_query($con, $query);