美好的一天。我正在尝试使用PHP + MySQL + HTML创建报告。请检查我的脚本
$data['bantu1'] = $this->db->query("select *from matapelajaran order by TipeMapel,Mapel asc")->result();
$data['siswa'] = $this->db->query("select nik,namasiswa from mastersiswa order by namasiswa asc")->result();
foreach($data['siswa'] as $sw) {
$data['nilai'][$sw->nik][] = $this->db->query("select * from rekapnilai where nik = '".$sw->nik."' ")->result();
}
每个都将返回此
Array
(
[0] => stdClass Object
(
[KodeMapel] => MPL20170114005517
[mapel] => BAHASA INDONESIA
)
[1] => stdClass Object
(
[KodeMapel] => MPL20170130031657
[mapel] => Bahasa Inggris
)
[2] => stdClass Object
(
[KodeMapel] => MPL20161211124354
[mapel] => MATEMATIKA
)
[3] => stdClass Object
(
[KodeMapel] => MPL20161205021910
[mapel] => Pendidikan Agama dan Budi Pekerti
)
[4] => stdClass Object
(
[KodeMapel] => MPL20161206085653
[mapel] => PKN
)
[5] => stdClass Object
(
[KodeMapel] => MPL20161211124453
[mapel] => BAHASA ARAB MELAYU
)
[6] => stdClass Object
(
[KodeMapel] => MPL20161206085544
[mapel] => Kertakes
)
)
echo "<pre>";print_r($data['siswa']); die();
Array
(
[0] => stdClass Object
(
[nik] => NIK003
[namasiswa] => Adi Suryono
)
[1] => stdClass Object
(
[nik] => NIK002
[namasiswa] => Anita Sari
)
)
echo "<pre>";print_r($data['nilai']); die();
Array
(
[NIK003] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[Idrekap] => 151
[nik] => NIK003
[nph] => 18
[npts] => 1
[npas] => 9
[IdPenilaian] => 15
[matapelajaran] => MPL20170114005517
)
[1] => stdClass Object
(
[Idrekap] => 201
[nik] => NIK003
[nph] => 16
[npts] => 8
[npas] => 8
[IdPenilaian] => 17
[matapelajaran] => MPL20161211124354
)
)
)
[NIK002] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[Idrekap] => 152
[nik] => NIK002
[nph] => 0
[npts] => 0
[npas] => 0
[IdPenilaian] => 15
[matapelajaran] => MPL20170114005517
)
[1] => stdClass Object
(
[Idrekap] => 202
[nik] => NIK002
[nph] => 0
[npts] => 0
[npas] => 0
[IdPenilaian] => 17
[matapelajaran] => MPL20161211124354
)
)
)
)
所以我已经用这种格式创建了一个html表。
和表格来源
<html>
<head>
<meta charset="utf-8">
<title>Rekap Nilai</title>
<link href="<?=base_url();?>assets_admin2/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="<?=base_url();?>assets_admin2/plugins/jQuery/jQuery-2.1.4.min.js" type="text/javascript"></script>
<script src="<?=base_url();?>assets_admin2/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<table width="100%" class="table text-center table-bordered" border="1">
<tbody>
<tr>
<td width="4" rowspan="3" align="center" valign="middle">No</td>
<td width="4" rowspan="3" align="center" valign="middle">Nama Siswa</td>
<td colspan="2" align="center" valign="middle">Spritual KI-1</td>
<td colspan="2" align="center" valign="middle">Spritual KI-1</td>
<?php foreach($bantu1 as $pela) {?>
<td colspan="4" align="center" valign="middle"><?=$pela->mapel;?></td>
<?php } ?>
<td width="6" rowspan="3" align="center" valign="middle">Jumlah Nilai</td>
<td width="6" rowspan="3" align="center" valign="middle">Rangking</td>
</tr>
<tr>
<td width="26" rowspan="2" align="center" valign="bottom">C</td>
<td width="39" rowspan="2" align="center" valign="bottom">P</td>
<td width="26" rowspan="2" align="center" valign="bottom">C</td>
<td width="33" rowspan="2" align="center" valign="bottom">P</td>
<?php foreach($bantu1 as $pela) {?>
<td colspan="2" align="center" valign="middle">Pengetahuan</td>
<td colspan="2" align="center" valign="middle">Keterampilan</td>
<?php } ?>
</tr>
<tr>
<?php foreach($bantu1 as $pela) {?>
<td width="10" align="center" valign="middle">C</td>
<td width="6" align="center" valign="middle">P</td>
<td width="6" align="center" valign="middle">C</td>
<td width="6" align="center" valign="middle">P</td>
<?php } ?>
</tr>
<?php
$y=0; foreach($siswa as $rslt){ $y++;?>
<tr>
<td><?=$y;?></td>
<td><?=$rslt->namasiswa;?></td>
<?php for($a=0;$a<2;$a++){ ?>
<td></td>
<td></td>
<?php } ?>
<?php foreach($bantu1 as $pela) {?>
<td></td>
<td></td>
<td></td>
<td></td>
<?php } ?>
<td></td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
请检查我的第一个和第二个查询结果。连接条件在这里
[KodeMapel] = [matapelajaran]
所以,我想要的结果是这样的
来自
的数字([nph] + [npts] + [npas])/ 4