我有一个数据库,我有这个代码从中获取信息并将其显示在表格上
<table border="1">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Gender</th><th>City</th></tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<%IF (x.value="ID") THEN%>
<td><a href="form7.asp?id=1">
<%Response.Write(x.value)%>
</td>
<%ELSE%>
<td>
<%Response.Write(x.value)%><a/>
</td>
<%END IF%>
<%next%>
</tr>
<%
rs.MoveNext
loop
%>
</table>
<%
rs.close
conn.close
%>
这将显示所有信息作为超链接我想要的只是其中一个显示为链接,其余假设为普通文本
例如我只想将id作为链接标记,其余的我希望将其显示为普通标记
怎么做?有人可以帮忙吗?
答案 0 :(得分:0)
你的代码太混乱了。
这就是你需要的。
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>City</th>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<%IF (x.value="ID") THEN%>
<td>
<a href="form7.asp?id=<%=rs(x.value)%>">
<%Response.Write rs(x.value)%>
</a>
</td>
<%ELSE%>
<td>
<%Response.Write rs(x.value)%>
</td>
<%END IF%>
<%next%>
</tr>
<%
rs.MoveNext
loop
%>
</table>
但是,如果您的查询返回的字段多于table head
,那么您的表格就会出错。
答案 1 :(得分:0)
<table border='1' cellspacing='2' cellpadding='2'>
<tr>
<th>ID</th>
<th>Name</th>
<th align=right>Age</th>
<th>Gender</th>
<th>City</th>
</tr>
<%
do until rs.EOF
response.write("<tr>") & vbCrLf
response.write("<td>")
response.write("<a href='form7.asp?id=" & rs("ID") & "'>")
response.Write rs("ID")
response.Write ("</a>")
response.Write ("</td>")
'======================
'NOTE: I'm breaking these next 4 columns down instead of using your "for" loop
'REASON: Inevitably you will want to format these differently from each other
'See the "age" column as an example.
'Also: easier to understand what is going on
'======================
response.write("<td>")
response.Write rs("Name")
response.Write ("</td>")
response.write("<td align=right>")
response.Write rs("Age")
response.Write ("</td>")
response.write("<td>")
response.Write rs("Gender")
response.Write ("</td>")
response.write("<td>")
response.Write rs("City")
response.Write ("</td>")
response.write("</tr>") & vbCrLf
rs.MoveNext
loop
rs.close
set rs=nothing
%>
</table>