Visual Basic 脚本 - HTML Table 输出不符合预期
Visual Basic Script - HTML Table output not as expected
我有一个 SQL 脚本可以输出我需要的数据。现在我需要在我的网站上的 HTML table 中显示它。我不确定我搞砸了什么,但数据不会显示在 table 中,而是全部显示在屏幕周围的一行中。
这是我目前的 "billing.asp" 页面(我会在解决这个问题后添加更多内容):
<%@ Language=VBScript %>
<html>
<head>
<title></title>
</head>
<body>
<%
dim startdate
startdate = request.form("datestart")
dim enddate
enddate = request.form("dateend")
%>
<%
dim dbconn
set dbconn = server.createobject("adodb.connection")
DBCONN.CommandTimeout = 30000
DBCONN.ConnectionTimeout = 30000
dbconn.open "dsn=*****;uid=*****;pwd=*****"
'if dbconn.errors.count > 0 then
' response.write "connection erros<br>"
' for each objerr in dbconn.errors
' response.write objerr.source & "<br>"
' response.write objerr.description & "<br>"
' next
'end if
dim billingtrans
dim sqlstr
sqlstr = "SELECT sq.*, sq.Total - sq.[Update] as Inquiry from ( select f.cityName, t.[employee], sum (t.TransactionCount) as Total, sum (case when ([format] in (23,25,38) or [format] between 400 and 499 or [format] between 800 and 899) then t.TransactionCount else 0 end) as [Update] FROM [log].[dbo].[TransactionSummary] t INNER JOIN [log].[dbo].[city] f on t.cityNo = f.cityNo and t.employee = f.employee and t.subno = f.subno where t.transactiondate between '" + startdate + "' and '" + enddate + "' group by f.cityName,t.employee ) sq"
set billingtrans = server.createobject("adodb.recordset")
billingtrans.open sqlstr, dbconn
%>
<table id="billing">
<tr>
<td>City</td>
<td>Employee</td>
<td>Total</td>
<td>Update</td>
<td>Inquiry</td>
</tr>
<%
while not billingtrans.eof
response.write "<tr>"
response.write billingtrans("cityName") & "</td>"
response.write billingtrans("employee") & "</td>"
response.write billingtrans("Total") & "</td>"
response.write billingtrans("Update") & "</td>"
response.write billingtrans("Inquiry") & "</td>"
billingtrans.movenext
wend
billingtrans.close
dbconn.close
%>
</table>
</body>
</html>
您没有关闭 <tr>
也没有打开 while
中的 </td>
。不相关,但您还应该在 header 行中使用 <th>
而不是 <td>
。
如果您不使用 response.write
.
,它的可读性也会更高(并且更不容易出错)
<table id="billing">
<tr>
<th>City</th>
<th>Employee</th>
<th>Total</th>
<th>Update</th>
<th>Inquiry</th>
</tr>
<% while not billingtrans.eof %>
<tr>
<td><% =billingtrans("cityName") %></td>
<td><% =billingtrans("employee") %></td>
<td><% =billingtrans("Total") %></td>
<td><% =billingtrans("Update") %></td>
<td><% =billingtrans("Inquiry") %></td>
</tr>
<%
billingtrans.movenext
wend
billingtrans.close
dbconn.close
%>
</table>
我有一个 SQL 脚本可以输出我需要的数据。现在我需要在我的网站上的 HTML table 中显示它。我不确定我搞砸了什么,但数据不会显示在 table 中,而是全部显示在屏幕周围的一行中。
这是我目前的 "billing.asp" 页面(我会在解决这个问题后添加更多内容):
<%@ Language=VBScript %>
<html>
<head>
<title></title>
</head>
<body>
<%
dim startdate
startdate = request.form("datestart")
dim enddate
enddate = request.form("dateend")
%>
<%
dim dbconn
set dbconn = server.createobject("adodb.connection")
DBCONN.CommandTimeout = 30000
DBCONN.ConnectionTimeout = 30000
dbconn.open "dsn=*****;uid=*****;pwd=*****"
'if dbconn.errors.count > 0 then
' response.write "connection erros<br>"
' for each objerr in dbconn.errors
' response.write objerr.source & "<br>"
' response.write objerr.description & "<br>"
' next
'end if
dim billingtrans
dim sqlstr
sqlstr = "SELECT sq.*, sq.Total - sq.[Update] as Inquiry from ( select f.cityName, t.[employee], sum (t.TransactionCount) as Total, sum (case when ([format] in (23,25,38) or [format] between 400 and 499 or [format] between 800 and 899) then t.TransactionCount else 0 end) as [Update] FROM [log].[dbo].[TransactionSummary] t INNER JOIN [log].[dbo].[city] f on t.cityNo = f.cityNo and t.employee = f.employee and t.subno = f.subno where t.transactiondate between '" + startdate + "' and '" + enddate + "' group by f.cityName,t.employee ) sq"
set billingtrans = server.createobject("adodb.recordset")
billingtrans.open sqlstr, dbconn
%>
<table id="billing">
<tr>
<td>City</td>
<td>Employee</td>
<td>Total</td>
<td>Update</td>
<td>Inquiry</td>
</tr>
<%
while not billingtrans.eof
response.write "<tr>"
response.write billingtrans("cityName") & "</td>"
response.write billingtrans("employee") & "</td>"
response.write billingtrans("Total") & "</td>"
response.write billingtrans("Update") & "</td>"
response.write billingtrans("Inquiry") & "</td>"
billingtrans.movenext
wend
billingtrans.close
dbconn.close
%>
</table>
</body>
</html>
您没有关闭 <tr>
也没有打开 while
中的 </td>
。不相关,但您还应该在 header 行中使用 <th>
而不是 <td>
。
如果您不使用 response.write
.
<table id="billing">
<tr>
<th>City</th>
<th>Employee</th>
<th>Total</th>
<th>Update</th>
<th>Inquiry</th>
</tr>
<% while not billingtrans.eof %>
<tr>
<td><% =billingtrans("cityName") %></td>
<td><% =billingtrans("employee") %></td>
<td><% =billingtrans("Total") %></td>
<td><% =billingtrans("Update") %></td>
<td><% =billingtrans("Inquiry") %></td>
</tr>
<%
billingtrans.movenext
wend
billingtrans.close
dbconn.close
%>
</table>