Muhammad Muqorrobin Muhammad Muqorrobin - 2 months ago 4
MySQL Question

error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax

I HAVE this query and error :


error message :

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'JOIN provinsi as provinsi ON provinsi.IDProvinsi =
lokasi_wisata.IDP' at line 3
select id_lw,judul_lw,left(deskripsi_lw,30)deskripsi_lw,latitude_lw,longitude_lw,
nama_p,nama_k,status_lw,gambar_lw from lokasi_wisata ORDER BY id_lw
ASC JOIN provinsi as provinsi ON provinsi.IDProvinsi =
lokasi_wisata.IDProvinsi JOIN kabupaten as kabupaten ON
kabupaten.IDKabupaten = lokasi_wisata.IDKabupaten where judul_lw like
'%%' limit 0, 10
Filename: C:/xampp/htdocs/mtma/application/models/pagination_model.php
Line Number: 21


query :

$sql = "select id_lw,judul_lw,left(deskripsi_lw,30)deskripsi_lw,latitude_lw,longitude_lw,
nama_p,nama_k,status_lw,gambar_lw
from lokasi_wisata ORDER BY id_lw ASC JOIN
provinsi as provinsi ON provinsi.IDProvinsi = lokasi_wisata.IDProvinsi JOIN
kabupaten as kabupaten ON kabupaten.IDKabupaten = lokasi_wisata.IDKabupaten where judul_lw like '%$st%' limit " . $start . ", " . $limit ;

Answer

SQL statements have to be in a certain order.

  1. SELECT
  2. FROM table
  3. JOIN tables
  4. WHERE
  5. GROUP BY
  6. HAVING
  7. ORDER BY
  8. LIMIT

So your query needs to look like this:

$sql = "select id_lw,judul_lw,left(deskripsi_lw,30)deskripsi_lw,latitude_lw,longitude_lw,
            nama_p,nama_k,status_lw,gambar_lw
            from lokasi_wisata
            JOIN provinsi as provinsi ON provinsi.IDProvinsi = lokasi_wisata.IDProvinsi
            JOIN kabupaten as kabupaten ON kabupaten.IDKabupaten = lokasi_wisata.IDKabupaten
            where judul_lw like '%$st%'
            ORDER BY id_lw ASC
            limit " . $start . ", " . $limit  ;
Comments