PDA

View Full Version : brows products


ahmedsoliman
10-15-2002, 10:25 PM
i have to brows the products in three columns ,so i tybed this code.
----------------------------------------------------------------------------
Set Com=Server.CreateObject("ADODB.Connection")
com.open("shop")
sql1="select prod_id,pname,picture from product where subcat="&subcat_id&""
set rs=com.execute(sql1)

while not rs.eof
%>
<tr>
<td ><A href="productdetail.asp?subcat_id=<%= rs(0) %>"><%= rs(1) %></a></td>

<% rs.movenext %>

<td ><A href="productdetail.asp?subcat_id=<%= rs(0) %>"><%= rs(1) %></a></td>

<% rs.movenext %>

<td ><A href="productdetail.asp?subcat_id=<%= rs(0) %>"><%= rs(1) %></a></td></tr>

<% rs.movenext
wend
%>
-------------------------------------------------------------------------------

but there an error, because if the number of product is 7 or 8 for examble the rs.movenext will act after eof of rs, so i want to exit the wile loop if rs.eof=true

whammy
10-16-2002, 12:00 AM
Try:

Do While NOT rs.EOF
'stuff here
rs.MoveNext
Loop

That always works for me. :)

ahmedsoliman
10-16-2002, 07:35 PM
i tried it but give the same error.

Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

not that i have to write rs.movenext three times in one loop to brows three products in one row of the table.

ksridhar69
10-16-2002, 07:44 PM
here is your answer

<%
DO WHILE NOT rs.EOF
%>
<tr>
<td><%=rs(0)%></td>
<td><%=rs(1)%></td>
<td><%=rs(2)%></td>
<td><%=rs(3)%></td>
</tr>
<%
rs.MoveNext
loop

Roy Sinclair
10-16-2002, 09:09 PM
All of the answers I see so far have missed the simple fact that the desired effect is to post 3 items per table row.

This should work:


Set Com=Server.CreateObject("ADODB.Connection")
com.open("shop")
sql1="select prod_id,pname,picture from product where subcat="&subcat_id&""
set rs=com.execute(sql1)
dim cnt
cnt = 0
while not rs.eof
call WriteProduct
rs.movenext
wend

sub WriteProduct
if cnt = 0 then
response.write "<tr><td>"
else
response.write "<td>"
end if
response.write "<a href=""productdetail.asp?subcat_id=" & rs(0) & """>" & rs(1) & "</a></td>"
cnt = cnt + 1
if cnt > 2 then
response.write "</tr>"
cnt = 0
end if
end sub

allida77
10-16-2002, 09:13 PM
<tr>
<%
Dim iRowCnt
iRowCnt = 1

while not rs.eof
If Not iRowCnt Mod 3 = 0 Then
Response.Write("<td >" & _
"<A href=""productdetail.asp?subcat_id="" & rs(dbfieldname) & "">"" & rs(dbfieldname) & "</a></td>")
Else
Response.Write("<td >" & _
"<A href=""productdetail.asp?subcat_id="" & rs(dbfieldname) & "">"" & rs(dbfieldname) & "</a></td></tr><tr>")
iRowCnt = iRowCnt + 1
rs.movenext
wend
%>

Didnt test but this is how I deal with columns. To change the columns just edit the Mod 3