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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fresh id with each looped record

Status
Not open for further replies.

ringadeal

Technical User
Jan 16, 2008
67
US
The following code contains an img tag id which will be repeated when applying a loop code. Using asp, how can I get a fresh ID which each repeated record:

Code:
<img src="images("url_img")"  id="colouratt1" >
 


Something like this might work:

Code:
Dim rs, data_source, no, SQL
no = 1 

If rs.Eof Then 
Response.write "Sorry there are no current records." 
Else 

'Loop through the records

Do while not rs.Eof 

response.write "<img src=" & images("url_img") &_
" id=colouratt" & no & ">"

no = no + 1
rs.movenext
Loop 

End If
 
Thanks for your response. I'm not sure how to insert your provided code into my existing code, as follows:
Code:
 <%
startrw = 0
endrw = HLooper3__index
numberColumns = 5
numrows = -1
while((numrows <> 0) AND (Not coloursAtt1.EOF))
	startrw = endrw + 1
	endrw = endrw + numberColumns
 %>
                        <tr align="center" valign="top">
                          <%
						  
While ((startrw <= endrw) AND (Not coloursAtt1.EOF))
%>
                          <td><a href="javascript:;" onmouseover="MM_showHideLayers('Layer1','','show');MM_showHideLayers('Layer1','','hide')"><img src="imagescript.asp?path=<%=(coloursAtt1.Fields.Item("url_img").Value)%>&amp;width=20" border="0" class="color_img" id="colouratt1" ></a>
                           </td> 
                          <%
	startrw = startrw + 1
	coloursAtt1.MoveNext()
	Wend
	%>
                        </tr>
                        <%
 numrows=numrows-1
 Wend
 %>
 
Looks like your startrw variable will be unique for each row - just use that concatenated onto "colouratt1", so it becomes
Code:
<%
myid="colouratt1" & Cstr(startrw)
%>
<td><a href="javascript:;" onmouseover="MM_showHideLayers('Layer1','','show');MM_showHideLayers('Layer1','','hide')"><img src="imagescript.asp?path=<%=(coloursAtt1.Fields.Item("url_img").Value)%>&amp;width=20" border="0" class="color_img" id="<%=myid%>" ></a>
                           </td>

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top