Solved

show only first 5

Posted on 2007-11-16
8
510 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
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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now