Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

databse query result into number representation 3

Status
Not open for further replies.

2cxc

Programmer
Aug 29, 2003
245
CA
i have a small databse that i'm pulling records from and was wondering how i can display the number of records returned, the sql is this:
sql = "SELECT DISTINCT ipA FROM captured"

and i'm currently displaying the records like so:
<form>
<b>
<font face=&quot;Verdana&quot; size=&quot;1&quot;>Total <i>Unique</i>
visitors:&nbsp;&nbsp;</b></font>
<%While Not rs.EOF%>
<%=rs.Fields(&quot;ipA&quot;)%>
<%
rs.MoveNext
Wend
%>
</form>

but now i don't want to display the records but rather the number of returned records. Thanks
 
Code:
<%
dim i
rs.movefirst
do until rs.eof
i = i + 1
rs.movenext
loop
response.write i & &quot; is the number of records returned.&quot;
%>

Or, if you want to add this into your existing code, you can do that as well and then print your records and then response.write the total number after you have finished your loop. Hope this helps.

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
also a smaller/less server intensive method is :

sql = &quot;Select Count(ipA) As ipACount From captured where ipA in (SELECT DISTINCT ipA FROM captured)&quot;

then later response.write rs(&quot;ipACount&quot;) if all you're looking for is a disctinct count
 
DreXor,

If I understand this correctly, this pulls a separate count at the same time it pulls the records which can then be used when needed? Definitely a less server intensive method and better answer. Will definitely keep this in mind for the future!

[thumbsup] - a star for you!

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Couple of options, mostly covered above :)

Select as you did, then count the number of records returned in your ASP (fengshui_1998's way is best)

OR

sql = &quot;SELECT Count(DISTINCT ipA) AS ipaCount FROM captured&quot;

Which will -only- get you the total, not the actual list of ipa's.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top