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

Loop 10 Records...

Status
Not open for further replies.

sladewilson

Programmer
Feb 14, 2002
90
US
I am building a price comparison ASP app. What would be the proper syntax to have the app show the best 10 prices for a given productID.

In other words I want to display the best 10 prices ONLY. There might be 30 prices for the given product but we only want to show the best 10.

----------------------------

This is my code for now.... it shows all records for a given Product ID.

<% DO WHILE NOT rsObj.EOF %>
<% Response.Write rsObj(&quot;StoreName&quot;) %> &nbsp; <% Response.Write rsObj(&quot;Price&quot;) %>
<%
rsObj.MoveNext
Loop
%>
 
I would add the prices to a array, then sort the array.
then you can use the loop to show the arrays first ten contents being the ten best prices A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
change the sql to sort by price and run the loop 10x Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I think you might want to do a sort in the SQL statement that grabs your record information.

Just do a sort descending and do a loop of 10 when doing the Response.Write. ====================================
I love people. They taste just like
chicken!

 
even better just populate the RS with the price values in the proper order by the ASC or DESC function then you already have the prices in order for writing them to the sreen.

so assuming the cheapest first do
SELECT * FROM table ORDER BY prices ASC

now loop thru and write them to 10 A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
ok.. everyone beat me. see what happens when the brain is working on slow speed. [lol] A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Ok, one more change :)
Use the TOP function to select the top 10 prices where > 0 ordered ascending :)

ie
SELECT TOP 10 * FROM table WHERE prices > 0 ORDER BY prices

This will cut down on your communication because it will only have to send back exactly what you need to display :)

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top