MrCreeky Posted July 27, 2008 Share Posted July 27, 2008 Hello, I want to try and filter the results shown on a webpage using php to only show events that are coming up after todays date. I entered this code in to the SQL but it errors and being code illiterate, I don't know where I'm going wrong. $query_rs1_events = "SELECT * FROM events WHERE `date` > (date ("Y F dS")); ORDER BY `key` ASC"; Could someone point me in the right direction? Quote Link to comment Share on other sites More sharing options...
peranha Posted July 27, 2008 Share Posted July 27, 2008 What are the errors you are getting?? Quote Link to comment Share on other sites More sharing options...
br0ken Posted July 27, 2008 Share Posted July 27, 2008 You've got a ; before the ORDER BY that shouldn't be there. Quote Link to comment Share on other sites More sharing options...
MrCreeky Posted July 28, 2008 Author Share Posted July 28, 2008 Hi, thanks for your help, I took the ; out but I'm still getting an error. Here is the full sql for this query: mysql_select_db($database_tbec, $tbec); $query_rs1_events = "SELECT * FROM events WHERE `date` > (date ("Y F dS")) ORDER BY `key` ASC"; $rs1_events = mysql_query($query_rs1_events, $tbec) or die(mysql_error()); $row_rs1_events = mysql_fetch_assoc($rs1_events); $totalRows_rs1_events = mysql_num_rows($rs1_events); The error I get is this one: Parse error: syntax error, unexpected T_STRING in /Users/Luke/Sites/tbec/index.php on line 39 Line 39 is the line: $query_rs1_events = "SELECT * FROM events WHERE `date` > (date ("Y F dS")) ORDER BY `key` ASC"; Quote Link to comment Share on other sites More sharing options...
MrCreeky Posted July 28, 2008 Author Share Posted July 28, 2008 If I declare the date it works fine like this but I need it to be dynamic and work from the current date that the user looks at the page. $query_rs1_events = "SELECT * FROM events WHERE `date` >= '2008-07-28' ORDER BY `key` ASC"; Quote Link to comment Share on other sites More sharing options...
MrCreeky Posted July 28, 2008 Author Share Posted July 28, 2008 Tried changing the field name from date to edate to avoid and conflicts with the reserved name but still no joy $query_rs1_events = "SELECT * FROM events WHERE `edate` >= date("Y-m-d") ORDER BY `key` ASC"; Quote Link to comment Share on other sites More sharing options...
br0ken Posted July 28, 2008 Share Posted July 28, 2008 you've got some unescaped brackets in your date() function. If this is the PHP date() function then you need to use it outside the question marks like this... $sql = "SELECT * FROM table WHERE date > ".date("Y F dS")." ORDER BY key ASC"; Alternatively if it's a MySQL date() function you use it like this... $sql = "SELECT * FROM table WHERE date > DATE('Y F dS') ORDER BY key ASC"; Quote Link to comment Share on other sites More sharing options...
MrCreeky Posted July 28, 2008 Author Share Posted July 28, 2008 Thanks for your help this got it working: $query_rs1_events = "SELECT * FROM events WHERE `edate` >= ".date("Ymd")." ORDER BY `key` ASC"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.