如何在编码器点火器中动态显示数据库列和数据



>我正在从数据库中获取表数据并将其显示在数据库中,但出现问题。 数据库中的测验列是在管理员添加测验分数时动态创建的。 现在,当我无法根据测验标题显示每列的数据时。

我能够使用 foreach 在标签中显示测验编号,但我无法显示该测验的分数。 请指导我。

//Manage Grades_model.php
public function GetAllQuizMarks()
{
	$this->db->select('*');
$this->db->from('quizmarks');

$query = $this->db->get();
	return $query->result();
}

//ManageGrades.php
//this is controller
public function GetAllQuizMarks()
{
$data['markslist']=$this->ManageGrades_model->GetAllQuizMarks();

$this->load->view('Manage/GetAllQuizMarks',$data);
}

//This is view file
<div class="panel-body">

<div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
<div class="row">
<div class="col-sm-12">
<table width="100%" class="table table-striped table-bordered table-hover dataTable no-footer dtr-inline" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info" style="width: 100%;">
<thead>
<tr role="row">
<th>Sr #</th>
<th>Name</th>
<th>Roll No.</th>


<!-- <th>Actions</th> -->
<?php 
$Counter=1;

?>
<?php 
foreach($markslist as $designation)
{
?><th><?php echo 'quiz'.$Counter;?></th>
<?php 
$Counter++;} 
?>

</tr>
</thead>
<tbody>
<?php 

$Counter1=1;

foreach($markslist as $designation)
{
?>   

<tr class="gradeA odd" role="row">
<td class="sorting_1"><?php echo $Counter;?></td>

<td class="sorting_1"><?php echo $designation->name;?></td>
<td class="sorting_1"><?php echo $designation->rollno;?></td>


<td class="sorting_1"><?php echo $designation->'quiz'.$Counter1;?></td>
<!-- <td class="center">
<div class="btn-group">

<a href="<?php echo base_url()?>Mid/EditMid/<?php echo $designation->Id;?>"><button class="btn btn-warning">Update</button></a>
<a href="<?php echo base_url()?>Mid/DeleteMid/<?php echo $designation->Id;?>"><button class="btn btn-danger">Delete</button></a>
</div>
</td> -->

</tr>
<?php
$Counter1++;
}
?>
</tbody>
</table></div></div></div>
<!-- /.table-responsive -->


</div>

在这里,这可能会对您有所帮助。

//This is view file
<div class="panel-body">
<div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
<div class="row">
<div class="col-sm-12">
<table width="100%" class="table table-striped table-bordered table-hover dataTable no-footer dtr-inline" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info" style="width: 100%;">
<thead>
<tr role="row">
<th>Sr #</th>
<th>Name</th>
<th>Roll No.</th>
<th>Quiz marks</th>
</tr>
</thead>
<tbody>
<?php
$Counter1=1;
foreach($markslist as $designation)
{
?>
<tr class="gradeA odd" role="row">
<td class="sorting_1"><?php echo $Counter1++;?></td>
<td class="sorting_1"><?php echo $designation->name;?></td>
<td class="sorting_1"><?php echo $designation->rollno;?></td>
<td class="sorting_1"><?php echo $designation->marks; //use you column name for mark mere?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>

最新更新