您好我需要以下列方式来处理来自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获取记录然后解决问题
<div class="listings">
<ul class="clear" id="navigation-feature2">
正如你所看到的那样,4条记录之后还应该增加navigation-feature2然后导航功能3。
谢谢
现在我有了这个并且没有做到这一点:
<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>
答案 0 :(得分:2)
如果mod 4为0,您需要询问计数器并更改列表编号。 或者一个简单的方法是添加第二个计数器,并每4个周期重置一次
像这样(简化代码):
<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>
答案 1 :(得分:1)
看起来你正在循环中关闭数据库查询
我建议将数据读入数组并循环遍历数据,而不是混合数据访问和渲染逻辑。
修改强>
怎么样
<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>
我也可能在这里犯错,但你又关闭了一个<div/> than you open and you should enclose the
(以及周围的<div/>) inside the
如果阻止。
答案 2 :(得分:0)
做到了......
<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>