VHS Posted March 28, 2007 Share Posted March 28, 2007 I am attempting to make a simple classifieds page. I need to create a record set to be used to display info using PHP & MySQL from a table where the current date is greater then the end date in the table and less then the start date. -table structure classified startdate_cla enddate_cla description_cla i.e. Display ALL form table classified where startdate_cla is less then the current date AND enddate_cla is greater than the current date. This should return everything from the table classified where the curent date is equal to or between the start date & end date. Here is my code, can anyone suggest how to make this work. I would appreciate it $today = date("Y-m-d"); $coldate_rsClassified = "-1"; if (isset($today)) { $coldate_rsClassified = (get_magic_quotes_gpc()) ? $today : addslashes($today); } mysql_select_db($database_connCMS, $connCMS); $query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla > %s ORDER BY ID_cla DESC", $coldate_rsClassified); $rsClassified = mysql_query($query_rsClassified, $connCMS) or die(mysql_error()); $row_rsClassified = mysql_fetch_assoc($rsClassified); $totalRows_rsClassified = mysql_num_rows($rsClassified); Quote Link to comment Share on other sites More sharing options...
poirot Posted March 28, 2007 Share Posted March 28, 2007 What happens when you try to run that piece of code? Oh, this: $query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla > %s ORDER BY ID_cla DESC", $coldate_rsClassified); could be replaced with: $query_rsClassified = "\"SELECT * FROM classified_ads WHERE enddate_cla > $coldate_rsClassified ORDER BY ID_cla DESC\""; Quote Link to comment Share on other sites More sharing options...
VHS Posted March 28, 2007 Author Share Posted March 28, 2007 This brings back everything in the table regardless of the end date Quote Link to comment Share on other sites More sharing options...
poirot Posted March 28, 2007 Share Posted March 28, 2007 This brings back everything in the table regardless of the end date Then there is probably something wrong with other parts of the code. Try to print the query before actually querying - see if it is what was supposed to be, it might shed some light on what is the problem. Quote Link to comment Share on other sites More sharing options...
VHS Posted March 28, 2007 Author Share Posted March 28, 2007 Ureka!! $query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla >= '$today' AND startdate_cla <= '$today'); This works perfectly only returning the the data that has a start date equal to or less then the current date AND having an end date equal to or greater than the current date. Thanks a bunch for pointing me in the right direction... 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.