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
    • 1k
    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.

    Array
    (
        [0] => Array
            (
                [question_id] => 13377
                [add_more_counter] => 0
                [front_title] => Text question
                [value] => first time fill
            )
    
    [1] => Array
        (
            [question_id] => 13377
            [add_more_counter] => 0
            [front_title] => Text question
            [value] => second time fill
        )
    
    [2] => Array
        (
            [question_id] => 13377
            [add_more_counter] => 0
            [front_title] => Text question
            [value] => text question 1
        )
    
    [3] => Array
        (
            [question_id] => 13378
            [add_more_counter] => 0
            [front_title] => Text box 2
            [value] => text question 2
        )
    )

    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
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: