我的示例表如下,
$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;
实际上,我想在Table:A(MySQL数据库)中显示Like Table:B。
以上代码,我可以显示1001到1009,但不显示剩余1003,1006,1008,1006。 另一方面,同一卷不能在一个(1003)之后保持另一个(1003)
如何在PHP代码或MySQL查询中解决它。
答案 0 :(得分:1)
试试这可能对你有帮助。
首先在模型文件中创建函数:
<?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));
}
然后调用控制器文件:
function index()
{
$data['student_detail'] = $this->yourmodeelname->getstudentinfo();
$this->load->view('your view file name');
}
然后进入查看文件:
if(isset($student_detail)) {
foreach($student_detail as $student)
{
echo $student['roll'];
echo '</br>';
echo $student['questions'];
}
}
?>