a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

SELECT COUNT

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> SELECT COUNT
Page: [1]
 
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
SELECT COUNT - 11/18/2005 11:51:27   
I am trying to Display the amount of total records from two tables in a MySQL database (separately) using ASP (just the total numebr of records). Can someone please point me in the right direcction for a tutorial on using SELECT COUNT or help with some quick code for accomplishing this.

Thanks in Advance
John
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:00:16   
The basic syntax for COUNT is as follows:

"SELECT CountOf(myFieldIWantToCount) AS TheNameThatIWantToReturn WHERE myFieldIWantToCriteria = (theValueIWantToUseAsACheckForCriteria)"

That help any?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to bigtime)
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:20:29   
I'm doing something wrong here Roger


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr

qry = "SELECT COUNTOF (id) AS TotalCount FROM WCust"

Set oRS = oConn.Execute(qry)

if not oRS.EOF then
while not oRS.EOF


wend
oRS.close
end if
Set oRs = nothing
Set oConn = nothing

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:26:33   
quote:

qry = "SELECT COUNTOF (id) AS TotalCount FROM WCust"


Ooops! Sorry. :) Try this one instead.

qry = "SELECT COUNT(id) AS TotalCount FROM WCust"

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to bigtime)
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:41:54   
Getting Closer Roger. No errors but still connot get it to display the total amount of rows.

connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr

qry = "SELECT COUNT(id) AS TotalCount FROM WCust"

Set oRS = oConn.Execute(qry)
reponse.write oRs.Fields ("TotalCount")
if not oRS.EOF then
while not oRS.EOF

 
wend
oRS.close
end if
Set oRs = nothing
Set oConn = nothing
%>




(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:44:48   
quote:

Set oRS = oConn.Execute(qry)
reponse.write oRs.Fields ("TotalCount")
if not oRS.EOF then
while not oRS.EOF


wend
oRS.close
end if
Set oRs = nothing
Set oConn = nothing


Can you try this instead?

Set oRS = oConn.Execute(qry)
if not oRS.EOF then
reponse.write oRs.("TotalCount")
end if
oRS.close
Set oRs = nothing
Set oConn = nothing

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to bigtime)
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:53:24   
Getting real close..I got this error now

Expected identifier 

/snapshot.asp, line 32 

reponse.write oRs.("TotalCount")
------------------^




(in reply to rdouglass)
Spooky

 

Posts: 26618
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: SELECT COUNT - 11/18/2005 13:59:32   
reponse.write oRs("TotalCount")

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bigtime)
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
RE: SELECT COUNT - 11/18/2005 14:05:09   
Spooky with that I get

Microsoft VBScript runtime error '800a01a8' 

Object required: '' 

/snapshot.asp, line 32 



Here is current code
connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr

qry = "SELECT COUNT(id) AS TotalCount FROM WCust"

Set oRS = oConn.Execute(qry)
if not oRS.EOF then
reponse.write oRs("TotalCount")
end if
oRS.close
Set oRs = nothing
Set oConn = nothing
%>



I didn't DIM TotalCount, but should that matter?

(in reply to Spooky)
Spooky

 

Posts: 26618
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: SELECT COUNT - 11/18/2005 14:08:07   
oops

response.write oRs("TotalCount")

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bigtime)
bigtime

 

Posts: 130
Joined: 10/15/2004
Status: offline

 
RE: SELECT COUNT - 11/18/2005 14:09:49   
I think I need to learn how to spell.

Thanks Spooky and Roger. You guys are the greatest.


(in reply to Spooky)
Spooky

 

Posts: 26618
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: SELECT COUNT - 11/18/2005 14:16:25   
I need to learn to cut and paste better ;-)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bigtime)
OscarSierra

 

Posts: 179
Joined: 5/14/2004
From: Norway
Status: offline

 
RE: SELECT COUNT - 6/17/2006 11:39:27   
You never need another forum for your solutions, even "cut and pate" is demonstrated here :)

However, is it possible to combine the SELECT COUNT and SELECT * on the same page/same query? I mean get a grid with all posts and then the number of posts ?

- Oystein

< Message edited by OscarSierra -- 6/17/2006 11:45:34 >

(in reply to Spooky)
yb2

 

Posts: 653
Joined: 1/30/2006
Status: offline

 
RE: SELECT COUNT - 6/17/2006 20:02:30   
SELECT COUNT(*) AS TotalCount FROM WCust

is used for counting the total number of rows in a table, though you may get the right result using the column specific way too if the column does not allow nulls.


quote:

However, is it possible to combine the SELECT COUNT and SELECT * on the same page/same query? I mean get a grid with all posts and then the number of posts ?


connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr

qry = "SELECT * From WCust"

Set oRS = oConn.Execute(qry)
if not oRS.EOF then
'get the count from the recordset
countfields = oRS.Fields.Count
Response.Write countfields
'do your stuff with the returned records here
'
end if
oRS.close
Set oRs = nothing
Set oConn = nothing
%>




_____________________________

it is natural for people not to see one's own faults, and to exaggerate other people's faults and failings.
Currently listening to: L'Enfer Des Formes by Stereolab

(in reply to OscarSierra)
OscarSierra

 

Posts: 179
Joined: 5/14/2004
From: Norway
Status: offline

 
RE: SELECT COUNT - 6/22/2006 14:23:06   
Thanks :)

(in reply to yb2)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> ASP and Database >> SELECT COUNT
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts