Johnny97 Johnny97 - 1 year ago 82
MySQL Question

php select from sql

I've a question. I want to select a row from SQL where my order_unlock_time >= '$timestamp'. The problem is that I don't get any date from my SQL Database. I've tried it to change the date and time in SQL to an older time but I get nothing.

$timestamp = date("Y-m-d H:i:s");
$abfrage = "SELECT * FROM test_related_orders WHERE user_id = '$user_id' AND order_unlock_time >= '$timestamp'";
$eating_result = mysqli_query($conn, $abfrage);

The User ID works perfectly but just without my "AND" statement for the time. The time in my order_unlock_time from my example is 2016-10-09 13:41:03 and my $timestamp has the time 2016-10-09 13:55:33. So when you think about it there should be a shown entry.

Answer Source

According to your data, timestamp (13:55:33) is bigger than order_unlock_time (13:41:03), so the query condition never will be true.

It should be

$abfrage = "SELECT * FROM test_related_orders WHERE user_id = '$user_id' AND order_unlock_time <= '$timestamp'";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download