Welcome Guest, Not a member yet? Register   Sign In
consecutive days resultset from db
#7

[eluser]obiron2[/eluser]
Two choices.
1)
Cribbing from above, which is actually quite a nice idea: Create a temporary table on the fly which holds a list of all the dates you are interested int. This requires a stored procedure on the database so is outside the MVC model of CI and its functionality would be hidden from the CI application codebase.

use this temporary table as the driving table and do a left outer join to the events. Generally if you have to use a right join you have not defined the query properly. You need to make sure you do an outer join so that you return the records in the temporary table where there is no data in the events table.

2)
Alternatively, as you are only interested in sequential dates, simply return your existing data set, ordered by date ascending.

loop through the records in the data set and check to see if the date is the same as the previous record. If it is not then compare it to the previous record + 1 day. If it still doesn't match then output 'no records for dd/mm/yyyy' and repeat the comparison until it does match.
Continue until the last record in the dataset.

If you need to potentially include dates that will fall outside the dataset, then you would need to start the date comparison with a known date and the first date in your dataset.

Obiron


Messages In This Thread
consecutive days resultset from db - by El Forum - 02-02-2009, 07:57 AM
consecutive days resultset from db - by El Forum - 02-02-2009, 06:58 PM
consecutive days resultset from db - by El Forum - 02-02-2009, 09:31 PM
consecutive days resultset from db - by El Forum - 02-03-2009, 05:25 AM
consecutive days resultset from db - by El Forum - 02-03-2009, 05:56 AM
consecutive days resultset from db - by El Forum - 02-03-2009, 07:41 AM
consecutive days resultset from db - by El Forum - 02-03-2009, 10:03 AM
consecutive days resultset from db - by El Forum - 02-03-2009, 10:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB