I am currently trying to fetch comments from the database table employee_trip_comments, however i am running into some problems and since i am not that familiar with SQL statements i am having a hard time fixing it.
In the SQL statement, i am using two INNER JOIN clauses to select records that have matching values in both tables.
The SQL statement is being called right away when the page loads/refreshes to be sure the data is always visible. When refreshing the page i get the following error: SQLSTATE: Integrity constraint violation: 1052 Column ‘week_end_date’ in where clause is ambiguous.
// get trip comments from the database $stmt = $pdo->prepare("SELECT comment_id, employee_trip_comments.employee_id, employee_trip_comments.trip_id, comment_datetime, comment_text, author_id, employees.full_name as 'author_name' FROM employee_trip_comments INNER JOIN employees ON employees.employee_id = employee_trip_comments.author_id INNER JOIN employee_trips ON employee_trips.trip_id = employee_trip_comments.trip_id WHERE employee_trip_comments.employee_id = :employeeID AND employee_trip_comments.trip_id = :tripID AND week_end_date = :weekEndDate ORDER BY comment_id DESC"); $stmt->execute([':employeeID' => $employeeID, 'tripID' => $tripID, ':weekEndDate' => $weekEndDate]); $tripComments = $stmt->fetchAll(PDO::FETCH_ASSOC);
I am not completely sure what exactly is going wrong here so i hope i can get some help from the community, Thanks in advance!