【发布时间】:2016-06-03 23:59:36
【问题描述】:
我正在使用 php 从数据库(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/> 或额外行。此外,数据库中的行没有任何空格。
我哪里出错了。感谢任何帮助/建议。提前致谢。
动态表格输出截图
【问题讨论】:
-
<tr FONT -
对不起,这是一个小错误。已编辑。
-
您查看过您的 HTML 源代码吗?它也是一个“工具”;-)
-
使用准备好的语句,伙计!另外,请给我们输出的 html,以便我们查看导致您的错误的原因。
-
我也附上了 HTML 源代码和输出的截图! :)
标签: php html sql-server-2012 html-table