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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.