My Example Tables are below,

$hdn_roll[0] =0;
$i =0;
foreach($results as $row):
$i++;
$roll = $row->roll;
$questions = $row->questions;
$hdn_roll[$i] = $roll;
$count_ad = array_count_values($hdn_roll);
$count_sp = $count_ad[$hdn_roll[$i]];
$j = 0;
if($hdn_roll[$i] != $hdn_roll[($i-1)]):
if($count_sp ==1):
create_row_after_balloting($roll,$questions);
endif;
else:
$j++;
$data['roll'.$j] = $roll;
$data['questions'.$j] = $questions;
endif;
endforeach;
Actually, I want to display Like Table:B from Table:A(MySQL Database).
Above Code, I can display 1001 to 1009 but Remain 1003,1006,1008,1006 are not display. On the other hand, Same Roll Can't stay another(1003) after one(1003)
How can i solve it in PHP code or MySQL Query.
studnet_info) WHEREstatus= 3. Table has 3 fields which are student_id(primary key) , roll,and questions. If it is possible using MySQL Query Or PHP code or Codeigniter. then Please help me @kruti