Returning an Array of rows within a Result Array. |
[eluser]defectivereject[/eluser]
Tried all night and day, and with Google. So turning to you guys for sanity each time the user has a lesson/course it is added to the DB via a course booking form, which puts data in several tables. 1st it adds the course to a DB table, with all the details and who's attending e.t.c. 2nd a separate query then runs to email the joining instructions to all those members attending(identified by course_id against a name). 3rd (Where i am stuck) What I'm looking for now is; the initial query has already added the following to a table called 'officecal' containing ID(PK), course_id, date_t and a user column so table would be id 1, course_id 1, user john, date 2010/01/01 id 2, course_id 1, user dave, date 2010/01/01 id 3, course_id 2, user john, date 2010/01/03 id 4, course_id 2, user dave, date 2010/01/03 id 5, course_id 2, user sue, date 2010/01/03 id 6, course_id 3, user sam, date 2010/01/04 what i'm trying to do is get the query to return an array of users per date (which i identify by course_id) and throw that into CI calendar My query is a simple one i know, but i can't get it to give me what i want, especially with what i have done with others up to this point! Code: function get_staff_training_dates($year, $month, $id) { What I'm trying to get this query to do is this(The 1 and the 3 below are stripped out of the date by the query above to identify purely the day of the month) Code: Array ( But all i can get back from the result is Code: Array ( It's seemingly returning only the last record per date in the db rather than all, per date. I'm obviously screwing up somewhere, any help would be great! Cheers in advance!
[eluser]Watermark Studios[/eluser]
Right now you're just replacing your key (the day) value with the most recent user value. You need to just add a nested array. I'm just taking a quick stab at this, but I would think you would want to do something like this: Code: $data[(int)substr($row['date_t'], 8, 2)][] = $row['user']; This would produce: Code: Array(
[eluser]defectivereject[/eluser]
Cheers Ignoring the funky data below as i did it to test the array faster i have now gotten the array i need Code: [26] => Array ( [0] => asd [1] => asd [2] =>
Tinker
[3] => sadasd [4] => dsaff [5] => dfgdfgdfg )
[eluser]defectivereject[/eluser]
Tis fine. I used Jagar's My_Calendar Library, and then changed the key part of my query to the following Code: $data[(int)substr($row['date_t'], 0, 4)][(int)substr($row['date_t'], 5, 2)][(int)substr($row['date_t'], 8, 2)][] = $row['data_t']; Seems to have done the trick, as its created an array as follows Code: Array Pic |
Welcome Guest, Not a member yet? Register Sign In |