Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with looping

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
0
0
PT
I guys, i'm having a problem with a loop, i'm going to put the code for you to see it, it's all working just great, however there's one thing that's driving crazy, i can't get the loop to work on the idfields of the DB, i want to pass the id for the next page in order to use it in the query but i have 6 recordsd on the DB and the id that's passed is always the first one, can someone help me?

<%
Dim idOpin
idOpin = opin(&quot;idopiniao&quot;)
Dim lastarticle
lastarticle = &quot;&quot;

do while not opin.EOF
If opin(&quot;idopiniao&quot;) <> lastarticle Then %>
<table width=450 border=1>
<tr>
<td bgcolor=#3399cc width=400>
<b><%=opin(&quot;titulo&quot;)%></b>
</td>
<td bgcolor=#3399cc>
<font size=2><a href=&quot;comt.asp?ID=<%=idOpin%>&quot; class=&quot;link&quot;>Comentar</a></font>
</td>
<br>
</tr>
<tr>
<td bgcolor=#dbf1ff colspan=2>
<!--#include file=&quot;splitopin.asp&quot; -->
</td>
</tr>
</table>
<% End If %>
<table border=1>
<% If opin(&quot;idcoment&quot;) <> &quot;&quot; Then %>
<tr>
<td width=440>
<font color=#3399cc>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i><!--#include file=&quot;splitcom.asp&quot; --></i></font>
</td>
</tr>
<% Else %>
<tr>
<td bgcolor=#3399cc width=383>
<b><%=opin(&quot;titulo&quot;)%></b>
</td>
<td bgcolor=#3399cc>
<font size=2><a href=&quot;comt.asp?ID=<%=idOpin%>&quot; class=&quot;link&quot;>Comentar</a></font>
</td>
<br>
</tr>
<td colspan=2 bgcolor=#dbf1ff>
<%=opin(&quot;opiniao&quot;)%>
</td>
</tr>
<tr>
<td>
<font color=&quot;red&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>Sem comentários</i><br></font>

</td>
</tr>
<% End If %>
</table>
<% lastarticle = opin(&quot;idopiniao&quot;)
opin.MoveNext
loop
%>


Thanks in advance

Herminio, Portugal
 
I think the problem is right at the top:

Code:
Dim idOpin
idOpin = opin(&quot;idopiniao&quot;)

This sets idOpin to a static value of the first id in the recordset - it won't change as you loop through. Try adding the Set keyword like this:

Code:
Set idOpin = opin(&quot;idopiniao&quot;)

This will make it update on each loop. --James
 
Thanks, it worked James, but no there's another problem, on the first three records the id is passed correctly, but on the fourth and all the others till the end of records the id isn't passed, i think this as something to do with the second link

Can you help me with this?
 
Help me, i'm still stuck with this question that i've posted yesterday.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top