[thelist] ASP/SQL Question Almost Got It!

Warden, Matt mwarden at mattwarden.com
Fri Sep 14 15:38:21 CDT 2001


You chose a way that I would not have chosen. First, let me show you why
you are missing some productdesc's. Then I'll let you know how I would do
it...

On Sep 14, J. Blanchard had something to say about Re: [thelist] ASP/SQL...

>Using this script ;
>
><%
>DIM pd
>pd = ""
>
>While Not product.EOF
>	If pd <> (product.Fields.Item("ProductDesc").Value) Then
>	pd = (product.Fields.Item("ProductDesc").Value)
>	response.write (pd & "<br>")
>		While pd = (product.Fields.Item("ProductDesc").Value)
>			response.write ((product.Fields.Item("ProductID").Value) & "<br>")
>			product.MoveNext
>		Wend
>	End If
>	product.MoveNext
>Wend
>%>	

Consider what happens the when the condition in your second while loop:

While pd = (product.Fields.Item("ProductDesc").Value)

is not met. When it is not met, that means we now are on a record that has
a new productdesc, right? Well, what's the next bit of code the gets
executed? it's:

product.MoveNext

You've just passed up a record!!! So, if you only have one productid in a
particular productdesc, then you'll pass up that productdesc altogether,
not just that particular productid. Here's how I'd do it:


<%
DIM pd
pd = ""

While Not product.EOF
	If pd <> (product.Fields.Item("ProductDesc").Value) Then
		pd = (product.Fields.Item("ProductDesc").Value)
		response.write (pd & "<br>")
	End If
	response.write((product.Fields.Item("ProductID").Value) & "<br>")
	product.MoveNext
Wend
%>

Hopefully that'll get ya working.


--
mattwarden
mattwarden.com





More information about the thelist mailing list