Teodor
Teodor

Reputation: 1305

classic ASP recordset problem

Hello i need to gater the data from db(MSSQL) in following way:

<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>

I have no ideea how to implement the recordset to get from 4 to for records and then to solve the problem of the
<div class="listings"> <ul class="clear" id="navigation-feature2"> as you could see after 4 records should increase also the navigation-feature2 and then navigation-feature3 .

Thank you

Now i have this and don't do the trick:

 <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>

Upvotes: 0

Views: 2393

Answers (3)

Teodor
Teodor

Reputation: 1305

Made it ...

  <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>

Upvotes: 0

Filburt
Filburt

Reputation: 18061

It looks like you're closing your database query within the loop

I'd recommend to read your data into arrays and loop over those rather than mixing data access and rendering logic.

edit

How about

<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>

I may err here too but you're closing one more <div/> than you open and you should enclose the (and surrounding <div/>) inside theIf block.

Upvotes: 1

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

You need to ask the counter if mod 4 is 0 and change the listing number. Or a simple way is to add a second counter, and reset it every 4 cycles

Like this (Simplified code):

<div id="slider">
  <div class="scroll" >
    <div class="scrollContainer">
      <%Set oRS2 = Server.CreateObject("ADODB.Recordset")
      oRS2.Open "..."
      Set picRS2 = Server.CreateObject("ADODB.Recordset")
      dim FeatureCounter 
      FeatureCounter = 1
      if not ors2.eof then
         do while not ors2.eof
         counter=counter+1

         If featureCounter = 1 then
            %>
            <div class="listings">
               <ul class="clear" id="navigation-feature<%= trim(featureCounter)%>">
            <%
          end if
          ''// not good to open a new recordset for every record, 
          ''// but leave it here because is not the scope of the answer
          picRS2.Open "..."
          ''// you should also check if picRS2 not EOF
           %>
             <li class="list1" id="feature-tab<%=counter%>">
                <a href="#"><img src="..."></a>
             </li>
           <%
           picrs2.close


           If FeatureCounter = 4 then
              FeatureCounter = 1 ''//reset the counter
              %>
                </ul>
                </div>
              <%
           else
              FeatureCounter = FeatureCounter + 1
           end if


           ors2.movenext
           loop

           end if%>

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

Upvotes: 2

Related Questions