Я использую Codeigniter, в котором у меня есть контроллер Studentcontroller и модель StudentModel. Я выбираю данные из процедур, и у меня от 4 до 5 переменных массива, каждая из которых хранит разные данные в соответствии с процедурами. Теперь эти переменные в основном данные для каждого столбца в таблице HTML. Теперь у меня возникла проблема, на самом деле я не знаю, как использовать foreach l oop таким образом, чтобы я мог показать все переменные данные в столбце таблицы.
Я использую контроллер, модель, HTML табличное представление. Пожалуйста, помогите мне. Контроллер -:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Students extends CI_Controller {
function __construct(){
parent:: __construct();
$this->load->model('StudentsModel');
}
/*******************************************************/
/************* Function for login process **************/
/*******************************************************/
public function index()
{
if ($this->session->userdata('SchoolLoggein') == TRUE){
$result['class_total_strn'] = $this->StudentsModel->class_total_strn();
$result['school_house_list'] = $this->StudentsModel->school_house_list();
// getting school house strength individual
$result['class_house_strn'] = $this->StudentsModel->class_house_strn();
$result['school_gender_list'] = $this->StudentsModel->school_gender_list();
$result['class_gender_strn'] = $this->StudentsModel->class_gender_strn();
$result['school_section_list'] = $this->StudentsModel->school_section_list();
$result['class_tptavailstrength'] = $this->StudentsModel->class_tptavailstrength();
$result['class_classtptNA'] = $this->StudentsModel->class_classtptNA();
// echo '<pre>';print_r($result['class_gender_strn']);exit;
$this->load->view('student',$result);
}
// end if userloggedin check
else {
$this->load->view('login');
}
}
}
?>
Модель -:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class StudentsModel extends CI_Model {
public function __construct() {
parent::__construct();
}
/****************************************************************/
/***************** Module for student reports *******************/
/****************************************************************/
// Calling procedure for class total strength
function class_total_strn(){
$classtotstrength = $this->db->query("CALL classtotstrength('".$_SESSION['session']."','".$_SESSION['msid']."','".$_SESSION['myDate']."','".$_SESSION['courseId']."')");
$class_strength = $classtotstrength->result_array();
$classtotstrength->next_result();
$classtotstrength->free_result();
if(!empty($class_strength)){
return $class_strength;
} else {
return '0';
}
}
// Calling procedure for school house list
function school_house_list(){
$schoolhouselist = $this->db->query("CALL schoolhouselist('".$_SESSION['msid']."')");
$all_schoolhouse = $schoolhouselist->result_array();
$schoolhouselist->next_result();
$schoolhouselist->free_result();
if(!empty($all_schoolhouse)){
return $all_schoolhouse;
} else {
return '0';
}
}
//Calling procedure for class house strength individual
function class_house_strn(){
$schoolhouselist = $this->db->query("CALL schoolhouselist('".$_SESSION['msid']."')");
$all_schoolhouse = $schoolhouselist->result_array();
$schoolhouselist->next_result();
$schoolhouselist->free_result();
foreach($all_schoolhouse as $school_house){
$classhousestrength = $this->db->query("CALL classhousestrength('".$_SESSION['session']."','".$_SESSION['myDate']."','".$_SESSION['msid']."','".$_SESSION['courseId']."','".$school_house['id']."')");
$house_strength[] = $classhousestrength->result_array();
$classhousestrength->next_result();
$classhousestrength->free_result();
}
if(!empty($house_strength)){
return $house_strength;
} else {
return '0';
}
}
// Calling procedure for school gender list
function school_gender_list(){
$schoolgenderlist = $this->db->query("CALL schoolgenderlist('".$_SESSION['msid']."')");
$gender = $schoolgenderlist->result_array();
$schoolgenderlist->next_result();
$schoolgenderlist->free_result();
if(!empty($gender)){
return $gender;
} else {
return '0';
}
}
// Calling procedure for gender strength
function class_gender_strn(){
$schoolgenderlist = $this->db->query("CALL schoolgenderlist('".$_SESSION['msid']."')");
$gender_list = $schoolgenderlist->result_array();
$schoolgenderlist->next_result();
$schoolgenderlist->free_result();
foreach($gender_list as $gender){
if(!empty($gender['gender'])){
$classgenderstrength = $this->db->query("CALL classgenderstrength('".$_SESSION['session']."','".$_SESSION['msid']."','".$_SESSION['myDate']."','".$_SESSION['courseId']."','".$gender['gender']."')");
$total_gender_stern[] = $classgenderstrength->result_array();
$classgenderstrength->next_result();
$classgenderstrength->free_result();
}
}
if(!empty($total_gender_stern)){
$result = [];
foreach ($total_gender_stern as $value) {
$result = array_merge($result, $value);
}
return $result;
} else {
return '0';
}
}
// Calling procedure for school gender list
function school_section_list(){
$schoolsectionlist = $this->db->query("CALL schoolsectionlist('".$_SESSION['msid']."','".$_SESSION['myDate']."')");
$school_selection_list = $schoolsectionlist->result_array();
$schoolsectionlist->next_result();
$schoolsectionlist->free_result();
if(!empty($school_selection_list)){
return $school_selection_list;
} else {
return '0';
}
}
// Function for fetch count of total transport
function class_tptavailstrength(){
// Calling procedure for get count all employees
$tottransport = $this->db->query("CALL classstptavailstrength('".$_SESSION['session']."','".$_SESSION['msid']."','".$_SESSION['myDate']."','".$_SESSION['courseId']."')");
$final = $tottransport->result_array();
$tottransport->next_result();
$tottransport->free_result();
if(!empty($final)){
return $final;
} else {
return '0';
}
}
// Function for fetch count of total transport
function class_classtptNA(){
// Calling procedure for get count all employees
$tottransport = $this->db->query("CALL classtptNA('".$_SESSION['session']."','".$_SESSION['msid']."','".$_SESSION['myDate']."','".$_SESSION['courseId']."')");
$final = $tottransport->result_array();
$tottransport->next_result();
$tottransport->free_result();
if(!empty($final)){
return $final;
} else {
return '0';
}
}
}
HTML Таблица -:
<div class="page email-page col-md-12">
<div class="row">
<table class="table mb-0 thbg">
<thead>
<tr class="Top">
<td rowspan="2" align="center">Class</td>
<td rowspan="2" align="center">Total</td>
<td colspan="2" align="center">Gender</td>
<td colspan="4" align="center">House</td>
<td colspan="2" align="center">Section</td>
<td colspan="4" align="center">Category</td>
<td colspan="2" align="center">Transport</td>
</tr>
<tr class="Top">
<td class="simple" align="center">Boy</td>
<td class="simple" align="center">Girl</td>
<td title="Green" align="center"> G </td>
<td title="White" align="center"> W </td>
<td title="Blue" align="center"> B </td>
<td title="Safforn" align="center"> S </td>
<td title="section" align="center"> S1 </td>
<td title="section" align="center"> S2 </td>
<td title="General" align="center"> Gen </td>
<td title="S.C." align="center"> S.C. </td>
<td title="S.T." align="center"> S.T. </td>
<td title="O.B.C." align="center"> O.B.C. </td>
<td class="simple" align="center">AVL</td>
<td class="simple" align="center">NA</td>
</tr>
</thead>
<tbody>
<tr>
<td align="center">
<a title="my class" class="style24" href="#">KG</a>
</td>
<td title="my total" align="center">
<a href="#">25</a>
</td>
<td title="Boys" align="center">
<a href="#">54</a>
</td>
<td title="Girls" align="center">
<a href="#">17</a>
</td>
<td align="center">
<a title="Green" href="#">22</a>
</td>
<td align="center">
<a title="White" href="#">8</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a title="A" href="#">30</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">27</a>
</td>
<td align="center">
<a href="#">3</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">21</a>
</td>
<td align="center">
<a href="#">9</a>
</td>
</tr>
<tr>
<td align="center">
<a title="my class" class="style24" href="#">KG</a>
</td>
<td title="my total" align="center">
<a href="#">25</a>
</td>
<td title="Boys" align="center">
<a href="#">54</a>
</td>
<td title="Girls" align="center">
<a href="#">17</a>
</td>
<td align="center">
<a title="Green" href="#">22</a>
</td>
<td align="center">
<a title="White" href="#">8</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a title="A" href="#">30</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">27</a>
</td>
<td align="center">
<a href="#">3</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">21</a>
</td>
<td align="center">
<a href="#">9</a>
</td>
</tr>
<tr>
<td align="center">
<a title="my class" class="style24" href="#">KG</a>
</td>
<td title="my total" align="center">
<a href="#">25</a>
</td>
<td title="Boys" align="center">
<a href="#">54</a>
</td>
<td title="Girls" align="center">
<a href="#">17</a>
</td>
<td align="center">
<a title="Green" href="#">22</a>
</td>
<td align="center">
<a title="White" href="#">8</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a title="A" href="#">30</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">27</a>
</td>
<td align="center">
<a href="#">3</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">0</a>
</td>
<td align="center">
<a href="#">21</a>
</td>
<td align="center">
<a href="#">9</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>