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.
Try this may be its help you.
First create function in model file:
<?php
function getstudentinfo()
{
//return $this->db->get_where('studnet_info', array('status' => 3));
return $this->db->distinct('roll')->select('roll,questions')->where(array('status' => 3));
}
Then call in controller file:
function index()
{
$data['student_detail'] = $this->yourmodeelname->getstudentinfo();
$this->load->view('your view file name');
}
Then get in view file:
if(isset($student_detail)) {
foreach($student_detail as $student)
{
echo $student['roll'];
echo '</br>';
echo $student['questions'];
}
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With