如何在查询结果的while循环内的特定条件下回显具有rowpan的行表?

时间:2018-08-14 03:03:22

标签: php mysql sql loops

我有这种报告

enter image description here

我想像上图一样进行报告。 我已经用此代码尝试过:

$id = 0;
    $id2 = 0;
    $no = 1;
    $q3 = mysql_query("SELECT * FROM pendidikan, unsur, subunsur WHERE pendidikan.id_sub = subunsur.id_sub AND subunsur.id_unsur = unsur.id_unsur AND pendidikan.nidn = $_GET[nidn]");
    $q4 = mysql_query("SELECT * FROM pendidikan, unsur, subunsur WHERE pendidikan.id_sub = subunsur.id_sub AND subunsur.id_unsur = unsur.id_unsur AND pendidikan.nidn = $_GET[nidn]");
    $data = array();
        while($d=mysql_fetch_assoc($q3)){
            $no++;
            if($id != $d['id_unsur']){
                $no = $no+1;
                echo"<tr>
                        <td>$d[kode_unsur]</td>
                        <td colspan='8'>$d[nama_unsur]</td>
                    </tr>";
                while($f=mysql_fetch_array($q3)){
                    if($id2 != $f['id_sub']){
                    echo"<tr>
                        <td rowspan='$no'>$d[kode_sub]</td>
                        <td colspan='8'>$d[nama_sub]</td>
                    </tr>";
                    }
                    $id2 = $f['id_sub'];
                    while($g=mysql_fetch_assoc($q4)){
                        if($g['id_sub'] == $f['id_sub']){
                            echo"<tr>
                                    <td>$g[no_butir]</td>
                                    <td>$g[uraian]</td>
                                    <td>$g[thn_smt_akademik]</td>
                                    <td>$g[tanggal]</td>
                                    <td>$g[satuan_hasil]</td>
                                    <td>$g[jml_vlm_kegiatan]</td>
                                    <td>$g[jml_angka_kredit]</td>
                                    <td>$g[bukti]</td>
                                </td>";
                        }

                    }
                }
            }
            $id = $d['id_unsur'];
        }

我应该怎么做,因为使用该代码,我使用相同的子A而不是B创建了这样的行:

enter image description here

任何帮助将不胜感激。谢谢。

0 个答案:

没有答案