Mysql php syntax error

I am struggling with a syntax error and I cannot find the problem.

this is my request

 $res2 = mysql_query("SELECT * FROM wp_postmeta PM1
                      WHERE PM1.meta_key = '_pronamic_google_maps_latitude'
                      AND PM1.post_id = '$id'
                      JOIN wp_postmenta PM2 
                      WHERE PM2.post_id = PM1.post_id 
                      AND PM2.meta_key = '_pronamic_google_maps_longitude'")
         or die(mysql_error());

and get this error:

You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use next to "JOIN wp_postmeta PM2" on line 3

may like it, someone can give me a hint what am i missing?

+3
source share
2 answers

You need to join first, and then the rest of the request. So something like

 $res2 = mysql_query("SELECT * FROM wp_postmeta PM1
                                  JOIN wp_postmenta PM2 on PM1.post_id = PM2.post_id
                                  WHERE PM1.meta_key = '_pronamic_google_maps_latitude'
                                  AND PM1.post_id = '$id'
                                  AND PM2.meta_key = '_pronamic_google_maps_longitude' 
                                   ") or die(mysql_error()) ;
+6
source

You have two where arguments and the connection order is wrong:

select ...
from ...
join ... on ...
where ... and ...
+3
source

All Articles