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 Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/ 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")."'"; Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698703 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. Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698714 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()"; Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698715 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 Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698757 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); ?> Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698762 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. Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698766 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 Link to comment https://forums.phpfreaks.com/topic/134229-solved-little-help-please/#findComment-698875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.