0

This is what I've tried, I know the syntax is wrong and there are too many brackets causing it not to work but I was just testing stuff!

Code:

$SQLGetLogs = $odb -> query("
    SELECT * FROM `logs` 
    WHERE (`time` + `date` > UNIX_TIMESTAMP() AND `stopped` = 1)
      AND `user` = '$MyUser'
");

Any ideas what to do?

How will I make this query work so all the clauses are included?

Pieter Geerkens
  • 11,775
  • 2
  • 32
  • 52
user3023566
  • 159
  • 1
  • 1
  • 12
  • What is the question? – i-- Jan 25 '14 at 05:07
  • Updated, sorry about that @i--. – user3023566 Jan 25 '14 at 05:08
  • 2
    With the code formatted, it is clearer what you are attempting. As the Boolean AND operator associates, the parenthesis in the WHERE clause are redundant, but that is not an error. What error message/condition are you seeing? – Pieter Geerkens Jan 25 '14 at 05:14
  • What is the value of $MyUser? Of what data type are the time & date fields? – i-- Jan 25 '14 at 05:14
  • Well there isn't essentially an error message, but it just doesn't display. If i remove the paranethesis around the first two clauses and just delete the third one it works, but I can't change any of them to OR, it has to be included as is. Not sure how to do it D: – user3023566 Jan 25 '14 at 05:16
  • Ill try to make it a bit more clear, the actual clauses work perfectly its just I'm trying to add a third clause to it which is "AND `stopped` = 1". How would I add it into the already working query? – user3023566 Jan 25 '14 at 05:16
  • My guess is that it has something to do with the stopped field. You sure there is a field named "stopped" in logs table, spelt correctly? Also you probably need to [enable your php errors](http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php) to see what is going on. – i-- Jan 25 '14 at 05:21
  • Already enabled php errors and no stopped is correct and everything, are you sure it has nothing to do with the setup? There are 2 and sections of the where clause. – user3023566 Jan 25 '14 at 05:25
  • @user3023566, as mentioned by P Geerkens, your mysql syntax is correct. How do you know that it does not work? May be it just does not return any records and your code shows nothing for such situation? Show the code that displays results. – i-- Jan 25 '14 at 05:47
  • Time + date? What's that? – Strawberry Jan 25 '14 at 08:14

0 Answers0