Return Empty Row If It Does Not Exist In The Db

I have a SQL query which retrieves one row per day for day1, day2, day3, day4, day5, day6 and day7. Day1 is always today, day2 tomorrow etc.

The query looks like this right now:

If one of the 7 rows (days) is missing (does not exist in the db) I would still like to have the resultset return a row with empty values for that date. Any ideas if I can achieve that in the SQL query directly?

I’ve tried to compare the dates (today and 6 days forward) in order to add an empty row to the resultset afterwards in the php code also, but no success. Any ideas?

It seems a bit wrong.

Couldn’t you just check the returned dates?

I think I’m getting closer now. I’m checking the predefined dates against the returned dates.

The table that I’m printing out contains the columns (predefined dates)

These columns should always be there no matter if the resultset is missing one of the dates. In reality, 2012-10-14 is missing from the resultset.

In the comparison below I am now getting out that $d3 is false and I therefore know that is the value missing. So I’m trying to insert an empty row but getting the error "Trying to get property of non-object ". This is indicating that I’m insert it in the wrong way into the resulset. Any ideas about this?

You’re trying to atribute to the database something of responsibility of your application logic.

Since you already know that the date doesn’t exist in the database, you can just print empty fields.

The error you’re getting is because you’re treating something that isn’t an object (it is null) as an object.

I’ve tried everything in the application logic without getting it to work. Instead I’d like to INSERT INTO the db if the row does not exist.

I keep getting SQL syntax error when trying this. Is it possible to solve it in the SQL statement?