Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > For Loop

Reply
Thread Tools

For Loop

 
 
D
Guest
Posts: n/a
 
      10-29-2004
Dear all, got a problem stuck here...

Given:

Title No_of_Download
A 6
B 8
C 9
D 10
E 0
F 1

I wanna display 5 result from the above table starting from the most no
of download, meaning Title E will not be display. How do i do it using a
For Loop???

Regards
cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Maarten
Guest
Posts: n/a
 
      10-29-2004

RS.OPEN "SELECT * FROM MyTable WHERE No_of_Download > 0 ORDER BY
No_of_Download ASC"

DO WHILE NOT RS.EOF
RESPONSE.WRITE RS("letter") & " - " & RS("No_of_download")
RS.MOVENEXT
LOOP

RS.CLOSE


<D> schreef in bericht news:%(E-Mail Removed)...
> Dear all, got a problem stuck here...
>
> Given:
>
> Title No_of_Download
> A 6
> B 8
> C 9
> D 10
> E 0
> F 1
>
> I wanna display 5 result from the above table starting from the most no
> of download, meaning Title E will not be display. How do i do it using a
> For Loop???
>
> Regards
> cheers
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Maarten
Guest
Posts: n/a
 
      10-29-2004
If you wish only the 5 most downloaded

RS.OPEN "SELECT TOP 5 * FROM MyTable WHERE No_of_Download > 0 ORDER BY
No_of_Download ASC"


 
Reply With Quote
 
D
Guest
Posts: n/a
 
      10-29-2004
May i know what is the code use for descending?? ASC is for acsending

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      10-29-2004
D wrote:
> May i know what is the code use for descending?? ASC is for acsending
>


In Access and SQL Server, the keyword is DESC. It may be different in other
databases depending on their degree of conformance to standard sql..

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      10-29-2004
Maarten wrote (and I repaired the order):
>> Title No_of_Download
>> A 6
>> B 8
>> C 9
>> D 10
>> E 0
>> F 1
>>
>> I wanna display 5 result from the above table starting from the most
>> no of download, meaning Title E will not be display. How do i do it
>> using a For Loop???

>
> RS.OPEN "SELECT * FROM MyTable WHERE No_of_Download > 0 ORDER BY
> No_of_Download ASC"


While I agree that the best solution is to bring back only the desired
records, this does not produce the desired outcome. One alternative:

SELECT Title, No_of_Download FROM MyTable WHERE Title IN (
SELECT TOP 5 Title FROM MyTable ORDER BY No_of_Download DESC
) ORDER BY Title ASC

In any case, neither solution meets the requested criterion: [For loop].
Should the data source not be so flexible, I can envision many looping
solutions, but none with a single loop. The closest I could come up with:

For each [Title]
Insert node into a binomial heap,
using an inverse key on [No_of_Download]
Next

Follow that up with 5 EXTRACT-MIN operations. This, of course, suffers from
the same problem as Maarten's solution -- it is ordered by frequency rather
than title**.

If JScript is the scripting language, I suppose we could use a clever
Array.sort().slice().sort() technique to avoid explicit looping entirely.




**Beyond the overhead needed to construct a binomial heap, that is.

--
Dave Anderson, waxing academic

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments