Reputation: 305
I have the following php select sql statement, which I can not get it to work. Please help:
$sql = "SELECT student_email, student_id, grades_id FROM student_table WHERE email_alert = 1 AND class_grade >= '$var' AND student_id in (
select student_id
from student_alerts
where CURRENT_TIMESTAMP < student_grad_date)" ;
In this SQL $var = 85
, student_id
is a primary key in student_table and a foreign key in the student_alerts table. Also student_id is referenced to the primary key in the student_table. I believe the error might be somewhere around CURRENT_TIMESTAMP
, the goal of which is to compare if today's date is not past the student's graduation date or it might be something in the syntax that I can not catch.
Thank you!
Upvotes: 1
Views: 74
Reputation: 305
Gotta love PHP. After the tips from @Shadow Fiend, i did some research and the correct syntax that worked was:
$sql = "SELECT student_email, student_id, grades_id FROM student_table WHERE email_alert = 1 AND class_grade >= '". mysql_real_escape_string($var) ."' AND student_id in ( select student_id from student_alerts where CURRENT_TIMESTAMP < student_grad_date)" ;
Upvotes: 0
Reputation: 319
You are using CURRENT_TIMESTAMP which provides a timestamp and student_grad_date is just a date.
You can use CURDATE() instead, which also provide you just the date
Upvotes: 1