You use a foreach loop. The example below is a quick one so there might be syntax errors. You can also assign the output to variables, instead of echoing it out.
You can store the $output into your database, however it may be difficult to analyze the data after... There is better method to store multiple values for data analysis but that's my 2 cents.