ztimer Posted April 11, 2014 Share Posted April 11, 2014 Hi. Need some help with the code. I have never done this type of grouping and need help with this one.The problem i'm facing is that i have one large table that contain multiple different things. For instance workers time log entry, vacation, sick leave, business trip and schedules.The layout is like "id, type, form_id, reserv, code, title, work_id, user_id, confirmer, confirmed_date_time, form_type, child_name, child_id_code, comment, group_id, date, day, end_date" and so on...What i would need to get is group this by date in php. Why? well so that i could count sum and do whatever with the values in php for per day..What have I done so far: $sql="SELECT * FROM datatable WHERE user_id = '".$_REQUEST['selected_user_id']."' AND date BETWEEN '".$_REQUEST['date_start']."' AND '".$_REQUEST['date_stop']."' ORDER BY date ASC, type ASC"; $result = mysql_query($sql); while($array = mysql_fetch_array($result)){ $data[$array[date]][$array[id]] = $array[type]; } foreach($data as $date => $value){ echo $date."<br>"; foreach($value as $id => $type){ echo "id: ".$id." type: ".$type."<br>"; Would like to get all the values for each id here. } } And this is what i get. Im getting only the id and the type and i dont know how to get the whole row based on the id. 2014-03-05 id: 44498 type: schedule <- I would like to have all the "id, type, form_id, reserv, code, title, work_id, user_id, confirmer, confirmed_date_time, form_type, child_name, child_id_code, comment," and so on values. id: 22911 type: timeclock 2014-03-06 id: 44499 type: schedule id: 22948 type: timeclock 2014-03-07 id: 22979 type: timeclock 2014-03-10 id: 44500 type: schedule id: 23016 type: timeclock 2014-03-11 id: 44501 type: schedule id: 23046 type: timeclock 2014-03-12 id: 44502 type: schedule id: 26953 type: sickness 2014-03-13 id: 44503 type: schedule id: 26954 type: sickness 2014-03-14 id: 44504 type: schedule id: 26955 type: sickness 2014-03-15 id: 26956 type: sickness 2014-03-16 id: 26957 type: sickness 2014-03-17 id: 44505 type: schedule id: 26958 type: sickness 2014-03-18 id: 44506 type: schedule id: 26959 type: sickness 2014-03-19 id: 26960 type: sickness If you can spot the problem then please help out. Thanks. Quote Link to comment Share on other sites More sharing options...
maxxd Posted April 11, 2014 Share Posted April 11, 2014 Your while loop is specifying which values you're using. Instead of this: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = $array['type']; } try this: while($array = mysql_fetch_array($result)){ $data[$array['date'][] = $array; } That should give you a date-indexed associative array of all the values in each row of the result set. Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 (edited) Your while loop is specifying which values you're using. Instead of this: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = $array['type']; } try this: while($array = mysql_fetch_array($result)){ $data[$array['date'][] = $array; } That should give you a date-indexed associative array of all the values in each row of the result set. The code does not work. I think there was a typo also. Missing ] before = Eather way it did not work Page crashed.. Edited April 11, 2014 by ztimer Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 Add type, form_id, reserv, code, title and so on in an array then loop the data. Try, while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'],$array['form_id'],$array['reserv'],so forth...) } Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 Add type, form_id, reserv, code, title and so on in an array then loop the data. Try, while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'],$array['form_id'],$array['reserv'],so forth...) } Ok that did not crash the page but how to retreive the extra values now.? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 After the while construct add the following and post the output: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'],$array['form_id'],$array['reserv'],so forth...) } // here echo '<pre>'.print_r($data, true).'</pre>'; Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 After the while construct add the following and post the output: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'],$array['form_id'],$array['reserv'],so forth...) } // here echo '<pre>'.print_r($data, true).'</pre>'; I can see that you are on the right track what i was looking for .. did try with some values and the array seems to work but im not sure how to use the array now like i intended to use. while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } echo '<pre>'.print_r($data, true).'</pre>'; the result im getting is Array ( [2014-04-01] => Array ( [23520] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-02] => Array ( [23554] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-03] => Array ( [23590] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-04] => Array ( [23627] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-07] => Array ( [23665] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-08] => Array ( [23689] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-09] => Array ( [23724] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) ) Can you spare some more time to make a example how to get the data like so that the for each date would be fefined as $date and inside foreach would be defined the $id and so on the other values so that i could echo out like foreach(.........){ echo $date."<br>"; <- the date value foreach(date value ){ the other values i needed as echo $id."".$user_id."".$form_id."".$someother.... } } I need to do some other calculations with these values and give like a lot of ifs and whiles to them and i'm more at home if i have defined them but im not so good at it yet or i have not come here to ask help. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 You need to use recursive function instead of bunch of nested loops. Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 You need to use recursive function instead of bunch of nested loops. Sorry its clearly out of my leage. Can you explain some more. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 11, 2014 Share Posted April 11, 2014 you need to store the whole $array to your $data array so you end up with an associative array of values to keep things clear in the code. also, unless you have more than one entry for any id on a date, you don't need to use the id as an additional array index. i would go back to the code maxxd gave in reply #2 and just fix the missing ] - while($array = mysql_fetch_array($result)){ $data[$array['date']][] = $array; } lastly, you don't need any sort of recursive function to process this data. you would however, need to show us your intended end result given any input data to get any help with how to do it. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 There are tons of examples how to make a recursive function in php, here it is. So for you if you want to find all data recursively to 2014-04-02 you can try, while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } function find_in_arr($key, $arr) { foreach ($arr as $k => $v) { if ($k == $key) { return $v; } if (is_array($v)) { foreach ($v as $_k => $_v) { if ($_k == $key) { return $_v; } } } } return false; } var_dump( find_in_arr('2014-04-02', $data) ); Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 (edited) you need to store the whole $array to your $data array so you end up with an associative array of values to keep things clear in the code. also, unless you have more than one entry for any id on a date, you don't need to use the id as an additional array index. i would go back to the code maxxd gave in reply #2 and just fix the missing ] - while($array = mysql_fetch_array($result)){ $data[$array['date']][] = $array; } lastly, you don't need any sort of recursive function to process this data. you would however, need to show us your intended end result given any input data to get any help with how to do it. The intended result should be used as a time management output. The table consist of multiple entries like if a worker makes a vacation request then a entry with a date for every date he/she is on vacation is added with type = vacation, if worker enters a time entry in the office the time start and time stop is entered with duration and if worker is on sick leave the dates with type sickleave is added. Now this is the table layout for short. What i would like is to get the worker to see his/her month data in table with sum for evey day. Lets say 01.01.2014 the worker has put her self to work for 5 hours but she only worked for 4,4 hours then overoll would be -0.6 so the worker knows she must do some overtime the next day. I need to get a array to give me a variable as date and after that i must have every table value as a variable $value that i could use as $value += $array[blablabla]; so at the next date it could stop and i could display the value. With all the sums i could do a total calculations in the end that shows how many hours there is to work or not and so on.. Edited April 11, 2014 by ztimer Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 (edited) There are tons of examples how to make a recursive function in php, here it is. So for you if you want to find all data recursively to 2014-04-02 you can try, while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } function find_in_arr($key, $arr) { foreach ($arr as $k => $v) { if ($k == $key) { return $v; } if (is_array($v)) { foreach ($v as $_k => $_v) { if ($_k == $key) { return $_v; } } } } return false; } var_dump( find_in_arr('2014-04-02', $data) ); Thank you for your help but this is not what i was looking for. Pleas read my post that i reply d before, after your posting. Edited April 11, 2014 by ztimer Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 (edited) As i see it by the code i think jazzman1 solution is so far the closest i need to go on. The only thing now is how i can use this ..? The code at the moment $sql="SELECT * FROM datatable WHERE user_id = '".$_REQUEST['selected_user_id']."' AND date BETWEEN '".$_REQUEST['date_start']."' AND '".$_REQUEST['date_stop']."' ORDER BY date ASC, type ASC"; $result = mysql_query($sql); while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['code'], $array['title'], $array['work_id'], $array['user_id'], $array['confirmer'], $array['form_type'], $array['form_type'], $array['child_name'], $array['child_id_code'], $array['comment'], $array['group_id'], $array['date'], $array['day'], $array['end_date'], $array['start'], $array['stop'], $array['duration'], $array['year'], $array['month'], $array['status'], $array['holiday'], $array['payment_type'], $array['days'], $array['entry_date_time']); } echo '<pre>'.print_r($data, true).'</pre>'; The output at the moment is Array ( [2014-04-01] => Array ( [23520] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-02] => Array ( [23554] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-03] => Array ( [23590] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-04] => Array ( [23627] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-07] => Array ( [23665] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-08] => Array ( [23689] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) [2014-04-09] => Array ( [23724] => Array ( [0] => timeclock [1] => [2] => [3] => 2 ) ) ) I now require a help on getting somethig like this.: foreach($data as $date => $value){ echo $date."<br>"; foreach(.....){ <-where the date is the $date $work_id = $array[the value of work id 0 where date = $date ]; $other values defined before. same way as before; and so on... i could make $sum_something += $duration; } echo $sum_something; <-inside of <tr></tr>; } Edited April 11, 2014 by ztimer Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 Because I don't have your data can you give the output of: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } function call_back_func($value,$key) { echo "The key $key has the value:"; foreach ($value as $v) { echo '<pre>'.print_r($v,true).'</pre>'; } } array_walk($data,"call_back_func"); Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 Because I don't have your data can you give the output of: while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } function call_back_func($value,$key) { echo "The key $key has the value:"; foreach ($value as $v) { echo '<pre>'.print_r($v,true).'</pre>'; } } array_walk($data,"call_back_func"); i get the resutts in a way The key 2014-04-01 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-01 [15] => [16] => [17] => 08:28:37 [18] => 17:09:50 [19] => 31273 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-02 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-02 [15] => [16] => [17] => 08:25:50 [18] => 17:06:04 [19] => 31214 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-03 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-03 [15] => [16] => [17] => 08:26:39 [18] => 17:02:48 [19] => 30969 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-04 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-04 [15] => [16] => [17] => 08:24:57 [18] => 16:51:09 [19] => 30372 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-07 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-07 [15] => [16] => [17] => 08:25:23 [18] => 17:08:09 [19] => 31366 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-08 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-08 [15] => [16] => [17] => 08:26:50 [18] => 17:07:52 [19] => 31262 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) The key 2014-04-09 has the value: Array ( [0] => timeclock [1] => [2] => [3] => [4] => [5] => [6] => 2 [7] => [8] => [9] => [10] => [11] => [12] => [13] => 1 [14] => 2014-04-09 [15] => [16] => [17] => 08:24:59 [18] => 17:01:23 [19] => 30984 [20] => [21] => [22] => 0 [23] => [24] => [25] => [26] => ) Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 11, 2014 Share Posted April 11, 2014 (edited) you are just throwing more code at this without a plan. listing out all your fields - $array['form_id'], array['reserv'], $array['code'], ... is the same as assigning the the whole $array, except assigning the whole array will give you the column names as the keys. you need to slow down. based on your description, you want to process the data per user_id, listing each date and the amount of time worked and display the total at the end? you would instead need to store the the values in $data using the 'user_id' as the primary key and sorting by the date (in the query) and if you have more than one entry per user_id on any date, you would need to use the date as a second array key. you would loop over the $data array, processing the entries for each user, then for each date for that user. Edited April 11, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 11, 2014 Share Posted April 11, 2014 But where is the value of $array['id'] I'm missing something Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 (edited) But where is the value of $array['id'] I'm missing something ups. $sql="SELECT * FROM datatable WHERE user_id = '".$_REQUEST['selected_user_id']."' AND date BETWEEN '".$_REQUEST['date_start']."' AND '".$_REQUEST['date_stop']."' ORDER BY date ASC, type ASC"; $result = mysql_query($sql); while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['id'], $array['form_id'], $array['reserv'], $array['code'], $array['title'], $array['work_id'], $array['user_id'], $array['confirmer'], $array['form_type'], $array['form_type'], $array['child_name'], $array['child_id_code'], $array['comment'], $array['group_id'], $array['date'], $array['day'], $array['end_date'], $array['start'], $array['stop'], $array['duration'], $array['year'], $array['month'], $array['status'], $array['holiday'], $array['payment_type'], $array['days'], $array['entry_date_time']); } while($array = mysql_fetch_array($result)){ $data[$array['date']][$array['id']] = array($array['type'], $array['form_id'], $array['reserv'], $array['user_id']); } function call_back_func($value,$key){ echo "The key $key has the value:"; foreach ($value as $v) { echo '<pre>'.print_r($v,true).'</pre>'; } } array_walk($data,"call_back_func"); The key 2014-03-03 has the value: Array ( [0] => schedule [1] => 44496 [2] => [3] => [4] => [5] => [6] => 6 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 08:10:00 [19] => 12:40:00 [20] => 4.5 [21] => [22] => [23] => [24] => [25] => [26] => [27] => 2014-02-26 09:11:39 ) Array ( [0] => timeclock [1] => 22862 [2] => [3] => [4] => [5] => [6] => [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => 1 [15] => 2014-03-03 [16] => [17] => [18] => 08:31:06 [19] => 12:42:44 [20] => 15098 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103489 [2] => [3] => [4] => [5] => [6] => 25 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 08:36:22 [19] => 08:42:57 [20] => 0.11 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103497 [2] => [3] => [4] => [5] => [6] => 14 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 08:43:00 [19] => 09:00:37 [20] => 0.294 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103501 [2] => [3] => [4] => [5] => [6] => 25 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 09:00:41 [19] => 09:39:59 [20] => 0.655 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103507 [2] => [3] => [4] => [5] => [6] => 6 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 09:40:00 [19] => 10:00:52 [20] => 0.348 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103519 [2] => [3] => [4] => [5] => [6] => 24 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 10:00:57 [19] => 11:21:02 [20] => 1.335 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103541 [2] => [3] => [4] => [5] => [6] => 32 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 11:21:07 [19] => 11:38:59 [20] => 0.298 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103554 [2] => [3] => [4] => [5] => [6] => 1 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 11:39:05 [19] => 11:39:17 [20] => 0.003 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103555 [2] => [3] => [4] => [5] => [6] => 23 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 11:39:26 [19] => 11:47:02 [20] => 0.127 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103561 [2] => [3] => [4] => [5] => [6] => 6 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-03 [16] => [17] => [18] => 11:47:06 [19] => 12:41:07 [20] => 0.9 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) The key 2014-03-04 has the value: Array ( [0] => schedule [1] => 44497 [2] => [3] => [4] => [5] => [6] => 6 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-04 [16] => [17] => [18] => 08:10:00 [19] => 16:25:00 [20] => 7.75 [21] => [22] => [23] => [24] => [25] => [26] => [27] => 2014-02-26 09:11:39 ) Array ( [0] => timeclock [1] => 22876 [2] => [3] => [4] => [5] => [6] => [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => 1 [15] => 2014-03-04 [16] => [17] => [18] => 07:59:21 [19] => 16:43:49 [20] => 31468 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103687 [2] => [3] => [4] => [5] => [6] => 25 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-04 [16] => [17] => [18] => 11:17:29 [19] => 11:22:21 [20] => 0.081 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Array ( [0] => timeflow [1] => 103690 [2] => [3] => [4] => [5] => [6] => 6 [7] => 141 [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => 2014-03-04 [16] => [17] => [18] => 11:22:24 [19] => 11:25:47 [20] => 0.056 [21] => [22] => [23] => 0 [24] => [25] => [26] => [27] => ) Edited April 11, 2014 by ztimer Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 11, 2014 Share Posted April 11, 2014 another reason to slow down (see my reply #17 above) is you are currently storing data using the $array['id'] as the $data array's second index. that's your row id from the table and is not organizing the data in a useful format. Quote Link to comment Share on other sites More sharing options...
Solution jazzman1 Posted April 11, 2014 Solution Share Posted April 11, 2014 (edited) It's a ugly but should work function call_back_func($value,&$key) { echo "The key $key has the value:"; foreach ($value as $k => $v) { echo $k; foreach ($v as $t) { echo $t."<br />"; } } } array_walk($data,"call_back_func"); Edited April 11, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
ztimer Posted April 11, 2014 Author Share Posted April 11, 2014 you are just throwing more code at this without a plan. listing out all your fields - $array['form_id'], array['reserv'], $array['code'], ... is the same as assigning the the whole $array, except assigning the whole array will give you the column names as the keys. you need to slow down. based on your description, you want to process the data per user_id, listing each date and the amount of time worked and display the total at the end? you would instead need to store the the values in $data using the 'user_id' as the primary key and sorting by the date (in the query) and if you have more than one entry per user_id on any date, you would need to use the date as a second array key. you would loop over the $data array, processing the entries for each user, then for each date for that user. What more plan do you need. ?? I have explained like in detailed the step by step what my intentions are. Do you really need that i make a drawing for you from the data i have and the output i would like. I only needed how to use the array results after the grouping and i do see that jazzman1 can see or read what i asked for help with.Dont get me wrong .. i am thankful that you read this thread and found the time to reply and im really trying my best to give all the info i know how to give to get help. I mean no disrispect and am really glad of all of your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.