Filling in last known value in MySQL recordset output when no data available
===

Consider the following three tables:

    daterange     stocks                               companies
    -----------   ----------------------------------   ----------------
    _date         stock_id  nyse_date   open   close   stock_id  name
    -----------   ----------------------------------   ----------------
    2011-03-11    1         2011-03-11  40.50  40.60   1         Alcoa
    2011-03-12    1         2011-03-14  40.62  41.04   2         Apple
    2011-03-13    1         2011-03-15  41.00  41.20   .           .
    2011-03-14    1         2011-03-16  41.15  42.00   .           .
    2011-03-15    1         2011-03-18  41.50  41.80   100       Xerox
    2011-03-16
    2011-03-17
    2011-03-18

`daterange` contains a continuous set of dates between march 1st and september 1st, 2011. Over the same period, `stocks` contains the `open` and `close` pricing information for 100 stocks. The stocks / companies are in `companies`. 

During the weekend, `2011-03-12` and `2011-03-13` and during holidays (for example, `2011-03-17`), no pricing information is available.

What I need is a list with `open` and `close` pricing information for _each of the dates in `daterange`_. Whenever there is a `_date` in `daterange` for which there is no pricing information in `stocks`, the last known pricing information has to be filled in.

So for Alcoa (`stock_id 1`) the output would have to be (* = taken from last know value):

    stock_id _date       open   close 
    ---------------------------------
    1        2011-03-11  40.50  40.60
    1        2011-03-12  40.50  40.60 *
    1        2011-03-13  40.50  40.60 *
    1        2011-03-14  40.62  41.04
    1        2011-03-15  41.00  41.20
    1        2011-03-16  41.15  42.00
    1        2011-03-17  41.15  42.00 *
    1        2011-03-18  41.50  41.80

Would this be possible to do in MySQL? Alternatively, I could use PHP to download the dates from `daterange` and loop through `stocks`, filling in whenever there is no entry for a specific date. But I guess MySQL would be a lot faster.

Any help is appreciated :-)