Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to generate report like pivot table from php 3d array on question_id base

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.02k
    Answer it

    Actually I am generating a report and print out answers under that question id. Like 13377 questiin id answered 3 times so i want to echo their answers underneath and the same for other question ids. All data is dynamic. Get unique questions id that will be table head and all answers of that id will be underneath. Its like pivot table report. So I am not getting the logic how to do that.

    1. Array
    2. (
    3. [0] => Array
    4. (
    5. [question_id] => 13377
    6. [add_more_counter] => 0
    7. [front_title] => Text question
    8. [value] => first time fill
    9. )
    10.  
    11. [1] => Array
    12. (
    13. [question_id] => 13377
    14. [add_more_counter] => 0
    15. [front_title] => Text question
    16. [value] => second time fill
    17. )
    18.  
    19. [2] => Array
    20. (
    21. [question_id] => 13377
    22. [add_more_counter] => 0
    23. [front_title] => Text question
    24. [value] => text question 1
    25. )
    26.  
    27. [3] => Array
    28. (
    29. [question_id] => 13378
    30. [add_more_counter] => 0
    31. [front_title] => Text box 2
    32. [value] => text question 2
    33. )
    34. )

    and want result exactly like this

     

 1 Answer(s)

  • Hello imran,

    As per my understanding you need to make changes in your mention array. Are you using database to manage the question and its related answers? Kindly check below array.

    array(

    [133422] => array( [0] => array([front_title] => 'my response' ), [1] => array([front_title] => 'my response' ), [2] => array([front_title] => 'my response' ) ),

    [133423] => array( [0] => array([front_title] => 'my response2' ), [1] => array([front_title] => 'my response2' ), [2] => array([front_title] => 'my response2' ) ) )

    In above code we created associated array in which we are using question id as key and includes different answer inside it.

    Thank you

    Deepak Verma

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: