Mr Chris Posted June 15, 2007 Share Posted June 15, 2007 Hi All, I have a question about my table: In my table I have a match_date and team_one_score and team_two_score Now I want to run two queries The first one: - Select All records that have not had anything in team_one_score and team_two_score filled in - And are greater than or equal to now() - But are for the next date(s) found. (so for example if today was the 14th it would return the 2, 20007-06-14 results, but not anything for 20007-06-15) Now i've tried: SELECT * FROM `results` WHERE match_date >= now() AND team_one_score ="" AND team_two_score ="" But how do I get it to output the first set of date(s) found as mentioned? And the second: - Select the last set of records in the db - Where the date less or equal than now() - Where there is something entered in team_one_score and team_two_score - But for only one date. (so for example it would return the 2 20007-06-13 results, but not 20007-06-12) Howver, I’m not sure at all on this query. Can anyone help? Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/55713-two-queries-can-you-help-please/ Share on other sites More sharing options...
paul2463 Posted June 15, 2007 Share Posted June 15, 2007 <?php $dateString = strtotime("Now"); // a timestamp of today $find_date = date("Y-m-d", $dateString); //todays date $hist_date_String = strtotime("-1 Day", $dateString); // take one day off todays timestamp ie yesterday $hist_date = date("Y-m-d", $hist_date_String); //yesterdays date //first query $query = "SELECT * FROM `results` WHERE match_date = '$find_date' AND team_one_score ='' AND team_two_score =''"; //second query $query = "SELECT * FROM `results` WHERE match_date = '$hist_date' AND team_one_score !='' AND team_two_score !=''"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55713-two-queries-can-you-help-please/#findComment-275320 Share on other sites More sharing options...
Illusion Posted June 15, 2007 Share Posted June 15, 2007 Paul - your first query always results yesterday status , I don't think this is what he requires. Chris - according to my understanding if you require status on a particular day why you are going to check this one "date less or equal than now()" and "date greater than or equal than now()" Quote Link to comment https://forums.phpfreaks.com/topic/55713-two-queries-can-you-help-please/#findComment-275349 Share on other sites More sharing options...
paul2463 Posted June 16, 2007 Share Posted June 16, 2007 if you wish to only bring out the fixture id's 8 and 9 ( both 2007-06-15) , the data in the database is a finite date just like a text string instead of a date, so check for that exact date by querying WHERE WHERE match_date = '$find_date' and $find_date is equal to , in this case "2007-06-15"), if there was a possibility of timestrings being involved then the best way to get around that is to use mysql built in date functions . Quote Link to comment https://forums.phpfreaks.com/topic/55713-two-queries-can-you-help-please/#findComment-275738 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.