only want to list 20 from Table

Discussion in 'C#' started by 1why, Oct 13, 2006.

  1. #1
    Please help,

    <%
    rs.movefirst
    while not rs.eof
    response.write rs("article")&<hr>
    rs.movenext
    wend
    %>

    what I want:

    To list the first 20 articles

    but maybe more than or less than 20 articles in table

    what to change the code
     
    1why, Oct 13, 2006 IP
  2. Froggie

    Froggie Well-Known Member

    Messages:
    665
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    120
    #2
    you could get all the records and only display 20 by keeping a counter
    like

    <%
    rs.movefirst
    dim counter
    while not rs.eof
    if counter < 20 then response.write rs("article")&<hr>
    counter= counter+1

    rs.movenext
    wend
    %>

    but this is a really bad way of doing it,
    just get only 20 records from the database by using the TOP keyword
    such as

    SELECT TOP 20 * FROM TableX WHERE....
     
    Froggie, Oct 13, 2006 IP
    1why likes this.
  3. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Froggie,

    it works now

    Thank you :)
     
    1why, Oct 13, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    you may do it while selecting also, in the SQL statement

    "SELECT TOP 20......"
     
    ludwig, Oct 14, 2006 IP
  5. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    how to do

    to get from top No.5 to the top No.20 ?

    please help
     
    1why, Oct 14, 2006 IP
  6. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #6
    This gives you the bottom 10 of the top 14, which is the same thing as a MySQL ” SELECT * from MyTable LIMIT 5, 10″. If you wanted to retrieve the next 10 records, you would simply do this:

     
    Talker, Oct 14, 2006 IP
    1why likes this.
  7. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sahel,

    Thank you very much.

    It creates more ways for query.

    :)
     
    1why, Oct 15, 2006 IP
  8. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #8
    Anytime m8, just thought i should share that with you :)
     
    Talker, Oct 15, 2006 IP