Jump to content

Two Queries - Can you help please?


Mr Chris

Recommended Posts

Hi All,

 

I have a question about my table:

 

res.jpg

 

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

 

Link to comment
Share on other sites

<?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 !=''";

?>

Link to comment
Share on other sites

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()"

Link to comment
Share on other sites

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 .

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.