繁体   English   中英

从SQL Server 2012和PHP填充的动态表中的额外行

[英]Extra rows in dynamic table populated from SQL Server 2012 and PHP

我正在使用php生成一个动态表,来自databasw(SQL Server 2012)。 使用下面粘贴的代码:

        <table class="table table-bordered" id="tb">
            <tr style="BACKGROUND-COLOR: DarkGrey ">
                <th colspan="4" style="text-align:Center;">Objectives and Targets </th>
            </tr>
            <tr class="tr-header">
                <th>Objectives / Measures</th>
                <th colspan="2">Targets / Achievements / Timelines</th>
                <th style="text-align:Center;width:1%;" rowspan="2">Weightage %</th>
            </tr>
            <tr>
                <th> </th>
                <th> </th>
                <th style="width:10%;"> Date </th>
            </tr>
            <tbody>
                    <?PHP
                        $myquery="  select replace(Objectives, '||<==', '') as Objectives, replace(Targets, '==', '') as Targets, replace(Weightage, '==', '') as Weightage, Corporate_Objective, Corporate_Objective_Weightage from Appraisal_Objectives WHERE Serial_Number='$Serial_Number' ORDER BY Row_Number asc";
                        $fetched=sqlsrv_query($conn,$myquery) ; 
                        if( $fetched === false ) { die( print_r( sqlsrv_errors(), true ));}
                        while($res=sqlsrv_fetch_array($fetched,SQLSRV_FETCH_ASSOC))
                        {   
                            $Corporate_Objective=$res['Corporate_Objective'];
                            $Weightage=$res['Weightage'];
                            $Objectives=$res['Objectives'];
                            $Targets=$res['Targets'];
                            $Corporate_Objective_Weightage=$res['Corporate_Objective_Weightage'];
                            echo "<tr><td>".$Corporate_Objective."</td>";
                            echo "<td></td>";
                            echo "<td></td>";
                            echo "<td><b>".$Corporate_Objective_Weightage."</b></td></tr>";
                            echo "<tr><td>".$Objectives."</td>";
                            echo "<td>".$Targets."</td>";
                            echo "<td></td>";
                            echo "<td>".$Weightage."</td></tr>";
                        }
                    ?>
            </tbody>
        </table>

问题

输出在每行之间创建了许多不需要的空白行! 我没有在代码中添加任何<br/>或多余的行。 此外,数据库中的行没有任何空格。

在此输入图像描述

我哪里可能出错了 感谢任何帮助/建议。 提前致谢。

ScreenShot的动态表输出

在此输入图像描述

我更改了我的SQL查询并使用了COALESCE 代码如下:

select Targets,target_date,ROW_NUMBER,
COALESCE(Corporate_Objective,Objectives) AS Objectives,
COALESCE(Corporate_Objective_Weightage,Weightage) AS Weightage
FROM Appraisal_Objectives WHERE Serial_Number like '%1153';

这删除了表中的所有空格:

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM