我正在尝试显示与特定ID(practice_Area_ID)相关联的所有公司。我无法弄清楚我是否设置了我的Do循环不正确或者我的SQL代码是否有问题。
问题是显示的结果只显示一家公司(当应该有5个不同的公司时),并且根据找到的实践区域数量(在本例中为5)重复多次。
换句话说,问题在于我没有展示5家不同的公司,而是只看到一家公司,但却列出了5次。
忽略我可怕的表格式...只是试图让结果显示在这里。
<%
intPractice_Area_ID = Request.QueryString("intPractice_Area_ID")
%>
(随机HTML)
<%
Set rsCompInfo = Server.CreateObject ("ADODB.Recordset")
compSQL = "SELECT Company_Main.Company_Name, Company_Main.Company_address, Practice_Areas.Practice_Area_ID FROM Practice_Areas INNER JOIN (Company_Main INNER JOIN Company_Practice_CK ON Company_Main.Company_ID = Company_Practice_CK.Company_ID) ON Practice_Areas.Practice_Area_ID = Company_Practice_CK.Practice_Area_ID WHERE Company_Practice_CK.Practice_Area_ID =" & intPractice_Area_ID
rsrsCompInfo.Open compSQL, Conn
strName = rsProdInfo("Company_Name")
strAddress = rsProdInfo("Company_Address")
%>
<table width="200" border="1">
<tr>
<th>Firm Name</th>
<th>Address</th>
</tr>
<%
if rsCompInfo.EOF then
Response.Write "No Records Found!"
else
strName = rsCompInfo("Company_Name")
strAddress = rsCompInfo("Company_Address")
Do While Not rsCompInfo.EOF
%>
<table border="1" cellspacing="0" cellpadding="2" width="602">
<tr>
<td width="560" valign="top"><font face="Verdana" size="3"><b><%= strName %></b></font><p>
<td width="560" valign="top"><font face="Verdana" size="3"><b><%= strAddress %></b></font><p>
<input type="hidden" name="intPractice_Area_ID" value="<%= intPractice_Area_ID %>">
</tr>
<td width="34"><td width="560"><font face="Verdana" size="2">
</table>
<%
rsCompInfo.MoveNext
Loop
end if
rsCompInfo.Close
set rsCompInfo = Nothing
Conn.Close
set Conn = Nothing
答案 0 :(得分:0)
这是绝对正确的:
Do While Not rsCompInfo.EOF
...
rsCompInfo.MoveNext
Loop
但是每次进行循环时都需要读取rsCompInfo的当前值:
<%= rsCompInfo("Company_Name") %>
<%= rsCompInfo("Company_Address") %>
'希望有所帮助!