I’m getting this error message when I try to load my page:
“Syntax error or access violation: 1064 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 ‘FROM titles INNER JOIN premieres ON dateid = premieres.id’ at line 3”
Here is my code:
try
{
$sql = 'SELECT titles.id, Title, name, directors.link, dateid
FROM titles INNER JOIN directors ON directorid = directors.id
FROM titles INNER JOIN premieres ON dateid = premieres.id';
$result = $pdo->query($sql);
correction: you have two FROMs and need only one, but you do need two ONs, otherwise you’ll get a cartesian crossproduct on the first join and have to filter most of them out
SELECT titles.id
, titles.Title
, titles.name
, directors.link
, titles.dateid
FROM titles
INNER
JOIN directors
ON directors.id = titles.directorid
INNER
JOIN premieres
ON premieres.id = titles.dateid
also, please note, it’s important that if your query has more than one table that you must qualify each column with the table it belongs to (see SELECT clause)
Thank you r937. I have a related question: I want to add links to Title, name, and format. I was able to add links to all three but when I click on them they only open the page linked to format when I want the links for Title and name to point to separate pages. Can you tell me where my error is? Here is part of the code for index.php: