Asp classic 经典ASP记录集问题

Asp classic 经典ASP记录集问题,asp-classic,Asp Classic,您好,我需要通过以下方式从db(MSSQL)中选通数据: <div id="slider"> <div class="scroll"> <div class="scrollContainer"> <div class="listings"> <ul class="clear" id="navigat

您好,我需要通过以下方式从db(MSSQL)中选通数据:

<div id="slider">
            <div class="scroll">

                <div class="scrollContainer">
                    <div class="listings">
                        <ul class="clear" id="navigation-feature">
                            <li class="list1" id="feature-tab1">
                                <a href="#"><img src="img/thumbnails/featured-1.jpg" alt="" title="" /><label>Francesca B&B</label>From €80</a>
                            </li>
                            <li class="list2" id="feature-tab2">
                                <a href="#"><img src="img/thumbnails/featured-2.jpg" alt="" title="" /><label>Condo Real Estate</label>$600</a>

                            </li>
                            <li class="list1" id="feature-tab3">
                                <a href="#"><img src="img/thumbnails/featured-3.jpg" alt="" title="" /><label>Washington House</label>$400</a>
                            </li>
                            <li class="list2" id="feature-tab4">
                                <a href="#"><img src="img/thumbnails/featured-4.jpg" alt="" title="" /><label>Cambridge</label>$650</a>
                            </li>

                        </ul>
                    </div>
                    <div class="listings">
                        <ul class="clear" id="navigation-feature2">
                            <li class="list1" id="feature-tab5">
                                <a href="#"><img src="img/thumbnails/featured-1.jpg" alt="" title="" /><label>Beach House</label>$900</a>
                            </li>
                            <li class="list2" id="feature-tab6">

                                <a href="#"><img src="img/thumbnails/featured-2.jpg" alt="" title="" /><label>Condo Real Estate</label>$600</a>
                            </li>
                            <li class="list1" id="feature-tab7">
                                <a href="#"><img src="img/thumbnails/featured-3.jpg" alt="" title="" /><label>Washington House</label>$400</a>
                            </li>
                            <li class="list2" id="feature-tab8">
                                <a href="#"><img src="img/thumbnails/featured-4.jpg" alt="" title="" /><label>Cambridge</label>$650</a>

                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

我不知道如何实现记录集,从4到for记录,然后解决

正如您在4条记录之后看到的,还应增加navigation-feature2,然后是navigation-feature3

多谢各位

现在我有了这个,不要耍花招:

 <div id="slider">
            <div class="scroll" >
                <div class="scrollContainer">

                         <%Set oRS2 = Server.CreateObject("ADODB.Recordset")

                        oRS2.Open "Select * FROM prop_home where packageid='2'",xDb_Conn_Str,3,3
                        Set picRS2 = Server.CreateObject("ADODB.Recordset")
                        if not ors2.eof then


                        %>
                <div class="listings">
                        <ul class="clear" id="navigation-feature">
                <%do while not ors2.eof
                counter=counter+1
     picRS2.Open "Select picture FROM pictures where propid='"&ors2("propid")&"'",xDb_Conn_Str

                %>
                            <li class="list1" id="feature-tab<%=counter%>">
                                <a href="#"><img src="admin/uploads/<%=picrs2("picture")%>" alt="" title="" style="height:auto !important;max-height:104px;max-width:170px;width:auto !important;"/><label><%=ors2("name")%>From €<%=ors2("pricemin")%></label></a>
                            </li>
                            <%
                            picrs2.close
                            ors2.movenext
                            loop

                            end if%>

                        </ul>
                    </div>

                </div>
            </div>
        </div>
    </div>

看起来您正在关闭循环中的数据库查询

我建议您将数据读入数组并在这些数组上循环,而不是混合数据访问和渲染逻辑

编辑

怎么样

<div id="slider">
    <div class="scroll" >
        <div class="scrollContainer">
<%
    Set oRS = Server.CreateObject("ADODB.Recordset")

    oRS.Open "Select ph.*, pic.picture FROM prop_home ph INNER JOIN pictures pic ON ph.propid = pictures.propid where ph.packageid='2'", xDb_Conn_Str, 3, 3

    If Not oRS.eof Then
%>
        <div class="listings">
            <ul class="clear" id="navigation-feature">

<%
         Do While Not oRS.eof
             counter = counter + 1
%>
                <li class="list1" id="feature-tab<%=counter%>">
                    <a href="#">
                        <img src="admin/uploads/<%=oRS("picture")%>" style="height:auto !important;max-height:104px;max-width:170px;width:auto !important;"/>
                        <label>
                            <%=oRS("name")%>From €<%=oRS("pricemin")%>
                        </label>
                    </a>
                 </li>
<%
             oRS.MoveNext
         Loop

         oRS.Close
%>
             </ul>
         </div>

<%

     End If
%>
     </div>
  </div>

我在这里也可能会出错,但您关闭的
比打开的多一个
,您应该将
(及其周围的
)括在
If块中。

看起来您正在关闭循环中的数据库查询

我建议您将数据读入数组并在这些数组上循环,而不是混合数据访问和渲染逻辑

编辑

怎么样

<div id="slider">
    <div class="scroll" >
        <div class="scrollContainer">
<%
    Set oRS = Server.CreateObject("ADODB.Recordset")

    oRS.Open "Select ph.*, pic.picture FROM prop_home ph INNER JOIN pictures pic ON ph.propid = pictures.propid where ph.packageid='2'", xDb_Conn_Str, 3, 3

    If Not oRS.eof Then
%>
        <div class="listings">
            <ul class="clear" id="navigation-feature">

<%
         Do While Not oRS.eof
             counter = counter + 1
%>
                <li class="list1" id="feature-tab<%=counter%>">
                    <a href="#">
                        <img src="admin/uploads/<%=oRS("picture")%>" style="height:auto !important;max-height:104px;max-width:170px;width:auto !important;"/>
                        <label>
                            <%=oRS("name")%>From €<%=oRS("pricemin")%>
                        </label>
                    </a>
                 </li>
<%
             oRS.MoveNext
         Loop

         oRS.Close
%>
             </ul>
         </div>

<%

     End If
%>
     </div>
  </div>


我在这里也可能会出错,但您关闭的
比打开的多一个
,您应该将
(及其周围的
)包含在
If块中。

您需要询问计数器mod 4是否为0并更改列表号。 或者一个简单的方法是添加第二个计数器,并每4个周期重置一次

如下(简化代码):



您需要询问计数器mod 4是否为0并更改列表编号。 或者一个简单的方法是添加第二个计数器,并每4个周期重置一次

如下(简化代码):


成功了

  <div id="slider">
            <div class="scroll">
                <div class="scrollContainer">
                     <%Set oRS2 = Server.CreateObject("ADODB.Recordset")

                        oRS2.Open "Select * FROM prop_home where packageid='2'",xDb_Conn_Str,3,3
                        Set picRS2 = Server.CreateObject("ADODB.Recordset")
                        if not ors2.eof then
                        dim FeatureCounter 
                          FeatureCounter = 1
                        othercounter=1 
                         do while not ors2.eof

                          counter=counter+1
                        if   featureCounter =1 then

        %>
                <div class="listings">
                         <ul class="clear" id="navigation-feature<%if othercounter <> 1 then  response.Write(othercounter) end if%>">
                   <%end if%>



                <%
     picRS2.Open "Select picture FROM pictures where propid='"&ors2("propid")&"'",xDb_Conn_Str

                If counter MOD 2 = 0 Then
                cl=2
                else 
                cl=1
                end if

                %>
                            <li class="list<%=cl%>" id="feature-tab<%=counter%>">
                                <a href="#"><img src="admin/uploads/<%=picrs2("picture")%>" alt="" title="" style="height:auto !important;max-height:104px;max-width:170px;width:auto !important;"/><label><%=ors2("name")%>From €<%=ors2("pricemin")%></label></a>
                            </li>
                           <% picrs2.close


       If FeatureCounter mod 4 = 0 then
         FeatureCounter = 1 ''//reset the counter

         othercounter = othercounter+1

 %>
                        </ul>
                    </div>
                    <%
        else
          FeatureCounter = FeatureCounter + 1
       end if


       ors2.movenext
       loop

       end if%>   </ul>
       </div>
                </div>
            </div>
        </div>
    </div>

成功了

  <div id="slider">
            <div class="scroll">
                <div class="scrollContainer">
                     <%Set oRS2 = Server.CreateObject("ADODB.Recordset")

                        oRS2.Open "Select * FROM prop_home where packageid='2'",xDb_Conn_Str,3,3
                        Set picRS2 = Server.CreateObject("ADODB.Recordset")
                        if not ors2.eof then
                        dim FeatureCounter 
                          FeatureCounter = 1
                        othercounter=1 
                         do while not ors2.eof

                          counter=counter+1
                        if   featureCounter =1 then

        %>
                <div class="listings">
                         <ul class="clear" id="navigation-feature<%if othercounter <> 1 then  response.Write(othercounter) end if%>">
                   <%end if%>



                <%
     picRS2.Open "Select picture FROM pictures where propid='"&ors2("propid")&"'",xDb_Conn_Str

                If counter MOD 2 = 0 Then
                cl=2
                else 
                cl=1
                end if

                %>
                            <li class="list<%=cl%>" id="feature-tab<%=counter%>">
                                <a href="#"><img src="admin/uploads/<%=picrs2("picture")%>" alt="" title="" style="height:auto !important;max-height:104px;max-width:170px;width:auto !important;"/><label><%=ors2("name")%>From €<%=ors2("pricemin")%></label></a>
                            </li>
                           <% picrs2.close


       If FeatureCounter mod 4 = 0 then
         FeatureCounter = 1 ''//reset the counter

         othercounter = othercounter+1

 %>
                        </ul>
                    </div>
                    <%
        else
          FeatureCounter = FeatureCounter + 1
       end if


       ors2.movenext
       loop

       end if%>   </ul>
       </div>
                </div>
            </div>
        </div>
    </div>


当我说data i reffer to image name from db、property name和price时,当我说data i reffer to image name from db、property name和pricepicrs2.close时,应该在循环内,否则您会收到错误消息