paulman888888 Posted November 25, 2008 Share Posted November 25, 2008 Hi guys; Ill get straight to the point! I am trying to use the DATE function but i don't now how to use it will Mysql. Ill explain; Am trying to use a PHP to get results from Mysql where the date is before today. I would like to say thankyou in advance. Paul Quote Link to comment Share on other sites More sharing options...
mtoynbee Posted November 25, 2008 Share Posted November 25, 2008 $query = "SELECT * FROM table WHERE date_field < '".date("Y-m-d")."'"; Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 can always use NOW() if want it before right now. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 25, 2008 Share Posted November 25, 2008 Mysql has a lot of built in date and time functions that can be used to do just about anything you want and they execute much faster than any slow parsed/tokenized/interpreted php code - $query = "SELECT * FROM table WHERE date_field < CURDATE()"; Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted November 25, 2008 Author Share Posted November 25, 2008 I tryed but for some reason it wont work. Heres my code <?php error_reporting(E_ALL); include'connection_1.php'; $strr = $_GET['only']; $strr = strtolower($strr); $allowedonly = array('upcoming', 'events'); if(isset($_GET['only'])){ if(in_array($strr,$allowedonly)){ if($strr='upcoming'){$opp='>';} elseif($strr='past'){$opp='<';} $sort="WHERE date_field ".$opp." '".date("Y-m-d")."'"; }else{$error='Search Not Found';$sort='';}}else{$sort='';} $result = mysql_query("SELECT * FROM chess_events '$sort'"); ?> and i get error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/site/events.php on line 46 thankyou for all the help! Paul Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 25, 2008 Share Posted November 25, 2008 I think your code is unnecessarily complicated. What about simplifying? <?php error_reporting(E_ALL); include'connection_1.php'; $query = "SELECT * FROM chess_events"; if (isset($_GET['only'])) { if ($_GET['only'] == 'upcoming') { $query .= " WHERE date_field > CURDATE()"; } elseif ($_GET['only'] == 'past') { $query .= " WHERE date_field < CURDATE()"; } } $result = mysql_query($query); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 That and you don't even show the code that shows you fetching the data. Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted November 25, 2008 Author Share Posted November 25, 2008 Thankyou flyhoney. I didn't think of that. Built the script the only way i new. Thanks mate Your amazing 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.