MySQL: WHERE query not working in PHP; working in MySQL

Matthew Lobo Willis

I'm baffled by this problem I'm having running a query through php. I'm hoping someone here can help me figure out what's going wrong. I want to query some data and filter it so only the results that were added after 11:00:00 on the day before and before 11:00:00 on the day the query are retrieved. Seems basic enough.

So I've made this code(abbreviated version):

 $result = myql_query("SELECT id_order, date_add, firstname, lastname FROM orders
 WHERE date_add >= '" . $yesterday . " 11:00:00' AND date_add <= '" . $today . " 11:00:00';");

 $today = date("Y-m-d");
 $yesterday = date('Y-m-d', time()-86400);

... but I'm given every row, not just the ones between those dates and times. What makes this really weird to me is that if I echo that same $result string, and then paste the results directly as a mySQL query it gives me what I'm looking for.

Any help figuring out why this isn't working as php would be greatly appreciated!

Jaylen

I have not tried it But try this

$today = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime("yesterday"));

$result = mysql_query('SELECT id_order, date_add, firstname, lastname FROM orders
WHERE date_add BETWEEN "' . $yesterday . ' 11:00:00" AND "'. $today . ' 11:00:00"');

And don't forget that those 2 variables have to be in the file before the query.

I hope this helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related