Solved

show only first 5

Posted on 2007-11-16
8
530 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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