如何回显值,但我希望它上面的行标题位置

时间:2016-11-15 15:38:40

标签: php html codeigniter-3

我有一张这样的桌子。

enter image description here

但我希望“借记卡”上的数据能够提供。专栏在它自己的位置。

这就是我想要的:

enter image description here

这是我目前的代码:

<?php
foreach ($jurnal->result_array() as $data){
    echo "
    <tr>
        <td>".$data['no_akun']."</td>
        <td>".$data['nm_akun']."</td>";
        if ($data['nm_akun'] == 'kredit'){
            echo "
                <td></td>
                <td>".$data['posisi_dr_cr']."</td>
            ";

        }else{
            echo "
                <td>".$data['posisi_dr_cr']."</td> 
                <td></td>
            ";
        }
    "</tr>
    ";
}
?>

3 个答案:

答案 0 :(得分:0)

td标记宽度与其包含的内容相同,因此空td将为0px宽度。

尝试在您的td标记中添加width =“25%”,如下所示:

<强>编辑:

foreach ($jurnal->result_array() as $data){
                echo "
                <tr>
                    <td width=\"25%\">".$data['no_akun']."</td>
                    <td width=\"25%\">".$data['nm_akun']."</td>";
                    if ($data['nm_akun'] == 'kredit'){
                        echo "
                            <td width=\"25%\"></td>
                            <td width=\"25%\">".$data['posisi_dr_cr']."</td>
                        ";

                    }else{
                        echo "
                            <td width=\"25%\">".$data['posisi_dr_cr']."</td> 
                            <td width=\"25%\"></td>
                        ";
                    }
                "</tr>
                ";
            }
        ?>

请注意,在String中输入width =“25%”,因此双引号字符必须具有\字符才能进行转义。

答案 1 :(得分:0)

试试这种方式。如果您使用的是bootstrap css,则可以在课程中使用text-left

<?php
foreach ($jurnal->result_array() as $data){
    echo "
    <tr>
        <td class='text-left'>".$data['no_akun']."</td>
        <td class='text-left'>".$data['nm_akun']."</td>";
        if ($data['nm_akun'] == 'kredit'){
            echo "
                <td class='text-left'></td>
                <td class='text-left'>".$data['posisi_dr_cr']."</td>
            ";

        }else{
            echo "
                <td class='text-left'>".$data['posisi_dr_cr']."</td> 
                <td class='text-left'></td>
            ";
        }
    "</tr>
    ";
}
?>

答案 2 :(得分:0)

使用以下代码:

<?php
foreach ($jurnal->result_array() as $data){
    echo "
    <tr>
        <td>".$data['no_akun']."</td>
        <td>".$data['nm_akun']."</td>";
        if ($data['nm_akun'] == 'kredit'){
            echo "
                <td>&nbsp</td>
                <td>".$data['posisi_dr_cr']."</td>
            ";

        }else{
            echo "
                <td>".$data['posisi_dr_cr']."</td> 
                <td>&nbsp</td>
            ";
        }
    "</tr>
    ";
}
?>