0

The first query works and displays the proper results. When I add an additional AND condition I get a "Trying to get property of a non-object" error.

I can successfully execute with one OR and one other condition.

Here is the query echoed:

SELECT * FROM scores 
WHERE (sortDate <= 20190629 AND sport = football) 
       AND (homeID = 4 OR awayID = 4) 
ORDER BY gameDate DESC

I'm sure the variable are passing through.

This one works fine:

$sql = "SELECT * FROM scores 
WHERE sortDate <= $today
AND (homeID = $teamID OR awayID = $teamID)
ORDER BY gameDate DESC";

This one gives an error (added AND):

$sql = "SELECT * FROM scores 
WHERE (sortDate <= $today AND sport = $sportID)
AND (homeID = $teamID OR awayID = $teamID)
ORDER BY gameDate DESC";
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
Anthony
  • 25
  • 6

1 Answers1

1

Try this

$sql = "SELECT * FROM scores 
WHERE (sortDate <= $today AND sport = '$sportID')
AND (homeID = $teamID OR awayID = $teamID)
ORDER BY gameDate DESC";

OR

$sql = "SELECT * FROM scores 
WHERE (sortDate <= $today) AND (sport = $sportID)
AND (homeID = $teamID OR awayID = $teamID)
ORDER BY gameDate DESC";
Rajendra Singh
  • 464
  • 3
  • 10
  • The first one worked with the single quotes (THANK YOU!). Why did it work? None of the others have single quotes. It was said that "sport is a string" what does that mean? – Anthony Jun 29 '19 at 11:37
  • It works for you fine. click the answer. It works because $sportID is the string (set of characters) as you tell it like football. – Rajendra Singh Jun 29 '19 at 11:40
  • 1
    It is much better to use prepared statements. All the problems with quotes are then gone. – Dharman Jun 29 '19 at 12:07