johnwayne77 Posted October 28, 2009 Share Posted October 28, 2009 Hello! I have a json table in mysql which stores questions and its answers for a test. What i want to do is to group the answers to its parent question like this: ex.: User1: question1: answer b, c question2: answer a,d User2: question1: answer c, a question2: answer b, a User3: question1: answer c, b question2: answer d,a Now i want to have a report that shows like this (ordered): question1 : answer c (3) ; answer b (2) ; answer a (1) question2 : answer a (3) ; answer d (2) ; answer b (1) I already decoded the json and with a foreach i get information like this: Question: 3 --> Answer: 1 Question: 29 --> Answer: 147 my code: $i=0; while ($row = mysql_fetch_assoc($sqljson)) { $i++; $json = $row['serialization']; $data = json_decode($json, true); foreach($data as $key1 => $value1) { foreach($value1 as $key2 => $value2) { echo "<b>Intrebare: </b>" . $key1 . " --> <b>Raspuns: </b>" . $value2 . "<br />"; } } echo "<hr>"; if ($i == '3') exit; } any ideas how i can group answers for questions ? i need it for some reporting Link to comment https://forums.phpfreaks.com/topic/179359-array-grouping/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.