Jump to content

[SOLVED] Simple question from a newbie


MrCreeky

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/116897-solved-simple-question-from-a-newbie/
Share on other sites

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";

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";

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.