I am trying to make my data by passing an exam id... the numbers are my student numbers. The data is stored in my db like this..
Here is my php code
$sql = "SELECT number, question_id, answer FROM `questions_answers` WHERE exam_id=" . $id;
$command = Yii::app()->db->createCommand($sql);
$data = $command ->query();
This is my for each loop, i am writing to csv file.
foreach($data as $result) {
fwrite($fp, $result['number'] . "," . $result['answer'] . "\r\n");
}
This is giving me result like this..
I want my result to be like this.. Where 2 is the answer of Q1 giving by number 3100000123, then 3 is answer of Q2, 1 is answer of Q3. Similarly for next student number.. I have tried different things but none of them worked for me. How can i achieve my data like this?