Phundament Phundament - 6 months ago 7
PHP Question

SQL query with results based on current date

I'm practicing on a php website with reservations. I've made three tabs on which I want to display reservations for today and for the coming week.
So far I have this mysql query:

$sql = "SELECT *
FROM users
LEFT JOIN reserveringen ON (users.userID = reserveringen.userID)
WHERE reserveringen.kamertype = 1
AND reserveringen.datum <= DATEADD(day,+7, GETDATE())";


but I it doesnt display any results

Edit:

I have made an if-else statement saying if there are results display them else echo a message saying "there are no reservations for the coming week". This is the query for showing all reservations and it runs just fine:

$sql = "SELECT *
FROM users
LEFT JOIN reserveringen ON (users.userID = reserveringen.userID)
WHERE reserveringen.kamertype = 1`

Answer

The function name DATEADD() is a TransactSQL function. In MYSQL it is called DATE_ADD() and the parameters are different as well

So this is more likely to work

$sql = "SELECT * 
        FROM users 
          LEFT JOIN reserveringen ON (users.userID = reserveringen.userID) 
        WHERE reserveringen.kamertype = 1 
          AND reserveringen.datum <= DATE_ADD(CURRDATE(), INTERVAL 7 DAY)";