Solved

show only first 5

Posted on 2007-11-16
8
547 Views
Last Modified: 2008-02-01
suppose i got some mysql/sql query
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC"

at the moment i view all records with
Do Until rstempo.EOF

how can i show only first 5?

0
Comment
Question by:sasha85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 13

Expert Comment

by:samic400
ID: 20300056

how about a simple counter like this:

dim i
do while not mRS.EOF
   i = i + 1
  if i > 5 then
     exit do
  else
    response.write mRS.fields(yourdata)
loop


0
 
LVL 9

Accepted Solution

by:
CCongdon earned 150 total points
ID: 20300058
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 0, 5"
0
 
LVL 3

Expert Comment

by:BioI
ID: 20300060
add at the end "limit 5":
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC limit 5"
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 13

Expert Comment

by:samic400
ID: 20300065
do while not mRS.EOF
   i = i + 1
  if i > 5 then
     exit do
  else
    response.write mRS.fields(yourdata)
  end if
 mRS.Movenext
loop
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 20300066
Of course, with mine you might still want to use your loop until EOF construct in case you get back less than 5 records.
0
 
LVL 16

Assisted Solution

by:DrNikon224
DrNikon224 earned 100 total points
ID: 20300067
Rewrite the query to limit to 5 results:

mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 5"
0
 
LVL 13

Assisted Solution

by:samic400
samic400 earned 150 total points
ID: 20300078
Looks like someone beat mean to it:

mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 0, 5"
0
 

Author Comment

by:sasha85
ID: 20300103
thank you guys:)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question