PHP表未创建
我正在使用php来查询sql server数据库并将结果写入屏幕。我想用表&我所有的echo语句TR/TD正在创建一个表中显示的结果,然而,当屏幕上显示的数据也出现运行在一起,就像下面:PHP表未创建
Employee EmployeeIDPrice1Price2Price3Price4Price5
等没有表结构。我应该在这个语法中改变什么,以便创建一个实际的表来显示结果?
if ($result = mssql_execute($proc))
{
$number_of_rows = mssql_num_rows($result);
if($number_of_rows > 0) {
echo '<table border="1">';
echo '<tr>';
echo ' <th bgcolor="#FFFFFF" >Employee </th>';
echo ' <th bgcolor="#FFFFFF">EmployeeID </th>';
echo ' <th bgcolor="#FFFFFF">Price1 </th>';
echo ' <th bgcolor="#FFFFFF">Price2 </th>';
echo ' <th bgcolor="#FFFFFF">Price3 </th>';
echo ' <th bgcolor="#FFFFFF">Price4 </th>';
echo ' <th bgcolor="#FFFFFF">Price5 </th>';
echo ' <th bgcolor="#FFFFFF">Price6 </th>';
echo ' <th bgcolor="#FFFFFF">Price7</th>';
echo ' <th bgcolor="#FFFFFF">Price8</th>';
echo ' <th bgcolor="#FFFFFF">Price9</th>';
echo ' <th bgcolor="#FFFFFF">Price10</th>';
echo ' <th bgcolor="#FFFFFF">Price11</th>';
echo '</tr>';
while ($Row = mssql_fetch_assoc($result))
{
echo '<tr><td>'.$Row['Employee'] .
'</td><td>'.$Row['EmployeeID'] .
'</td><td>'."$".round($Row['Price1']) .
'</td><td>'."$".round($Row['Price2']) .
'</td><td>'."$".round($Row['Price3']) .
'</td><td>'."$".round($Row['Price4']) .
'</td><td>'."$".round($Row['Price5']) .
'</td><td>'."$".round($Row['Price6']) .
'</td><td>'."$".round($Row['Price7']) .
'</td><td>'."$".round($Row['Price8']) .
'</td><td>'."$".round($Row['Price9']) .
'</td><td>'."$".round($Row['Price10']) .
'</td><td>'."$".round($Row['Price11']) .
'</td></tr>';
}
echo '</table>';
}
编辑
这是我的输出样子,甚至在CELLPADDING加入后=“5” ......没有一个明确定义的表像我使用HTML的话table
和td
tr
当预期 - 意味着所有的数据只是在一起流血,而不是像我想的那样定义表格。
这是不正确的结构
必须是这样的:
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
echo '<table border="1" cellpadding="1" style="width: 100%;">';
增加的cellpadding的要求。
但我建议你阅读css作为未来的改进。
此外,该行有语法错误:'</td><td>."$".round($Row['Price6']) .
它应该是: - 你解决了这个问题,因为我贴!'</td><td>'."$".round($Row['Price6']) .
甚至更好:'</td><td>$'.round($Row['Price6']) .
只是为了澄清,cellpadding =“1”会给你一个像素的细胞周围的空间。 cellpadding =“5”会给你5个像素等。这个答案有帮助,或者你还没有看到它显示你想要的? – craigmayhew
仍然不是我以后的输出。它只是一起跑,就像书中的文字一样。我在一个干净有序的表格之后,像下面提供的w3schools链接。 – BellHopByDayAmetuerCoderByNigh
即使cellpadding =“5”?你能给你实际的html输出吗? – craigmayhew
从SQL Server甚至以为我返回结果我不强迫使用echo语句? – BellHopByDayAmetuerCoderByNigh
如果我不使用echo语句,当我尝试访问该页面时,出现500错误。 – BellHopByDayAmetuerCoderByNigh