473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

For Loop

D
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!
Jul 21 '05 #1
5 1278

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:%2***************@TK2MSFTNGP11.phx.gbl...
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!

Jul 21 '05 #2
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"
Jul 21 '05 #3
D
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!
Jul 21 '05 #4
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.
Jul 21 '05 #5
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.
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.