For Loop

Discussion in 'ASP General' started by D, Oct 29, 2004.

  1. D

    D Guest

    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!
     
    D, Oct 29, 2004
    #1
    1. Advertising

  2. D

    Maarten Guest

    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:%...
    > 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!
     
    Maarten, Oct 29, 2004
    #2
    1. Advertising

  3. D

    Maarten Guest

    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"
     
    Maarten, Oct 29, 2004
    #3
  4. D

    D Guest

    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!
     
    D, Oct 29, 2004
    #4
  5. 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.
     
    Bob Barrows [MVP], Oct 29, 2004
    #5
  6. 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.
     
    Dave Anderson, Oct 29, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,413
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,288
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    715
    Remon van Vliet
    Jun 15, 2005
  4. Byte
    Replies:
    4
    Views:
    437
  5. Isaac Won
    Replies:
    9
    Views:
    449
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page