I am working on a PHP program which requires a series of SQL related outputs and I was hoping that SQL could do most of the work form me.
I have a table structured for the sake of this question with this type of data and headers
Note : ID is used for specific entries and is Auto Incremented
Note : Title Section is used to isolate data for specific projects
Note : Person may be duplicated for a specific project
Note : Date will not be duplicated but not necessarily be organized
Note : For the purpose of this question assume data is not organized as nicely and Ordering to occur in the SQL statements
When I use phpmyadmin sql database
SELECT * FROM `This_Table` WHERE `Title` = 'Project_1' ORDER BY `Working_Date` ASC, `Worker_Name` ASC
This is the correct output that I want.
Here comes the issue, I want to use something close to array_agg but there was confusion about making arrays of arrays (2 dimension arrays) but what I want to do is use a SQL query on the new table such that I can generate the following arrays.
QUESTION : Can SQL provide an output that would allow for me to have the following arrays based on the above datasets?
#Unique Dates Organized ASC
$Date = array('2020-04-19', '2020-04-20', '2020-04-21', '2020-04-22', '2020-04-23', '2020-05-26', '2020-06-01');
#Names which by default will be unique in their own sub array by date
#so in short a 2 dimensional array with Date then Persons
$Person = array(array('Joe', 'Mark'), array('Mark'), array('Joe', 'Mark'), array('Joe', 'Mark'), array('Mark'), array('Joe'), array('Joe'))
It sounds like a ton of work but if SQL could give me that kind of output accurately it would make some of my coding significantly easier. At this point I have to output the rows of data from SQL into my PHP and build the arrays within the PHP code itself rather than have SQL output the arrays like this and for larger databases it takes a significant amount of time to build the array itself let alone calling for unique data.