I want to get all the films whose genre is equal to ID_GENRE = 8
. This is the query that I'm doing:
http://l4c.me/fullsize/2-tablas-1434140362.png
$query_GetSimilar = sprintf("SELECT * FROM z_movie,z_movie_genre ORDER BY z_movie.visits DESC WHERE z_movie_genre.id_genre = 8 LIMIT 18");
$GetSimilar = mysql_query($query_GetSimilar, conect::dbconect()) or die(mysql_error());
$row_GetSimilar = mysql_fetch_assoc($GetSimilar);
$totalRows_GetSimilar = mysql_num_rows($GetSimilar);
But I jump the next error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE z_movie_genre.id_genre = 8 LIMIT 18' at line 1
Note:
WHERE
should be first beforeORDER BY
INNER JOIN
to get two connecting tables, assuming that they have connecting id/column.For example, both
z_movie
andz_movie_genre
table has the columnid_genre
to connect each other, you can try this: