ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old August 26th, 2003, 11:11 AM
artimador artimador is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 artimador User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post Help with blogger... Counting total rows in database table.

Hello,

I am creating a simple one page blogger for page visitors to 'rant' so to speak... This is a remake of the old one and I've got about 49 pages of 5 entries each from the old one...

I need to make different dynamic pages using querystrings in the url which is simple enough. The page numbers are dynamic based upon totall records in the 'rants' table divided by 5 entries per page...

Previously I've used a 'for next' statement nested in an 'if then' to actually go throuch each record and count it but it taxes the server while proccessing other parts of the page...

MY QUESTION IS: is there a SQL command that I can use for my ODBC connection to get the total number or rows in the 'rants' table?

Reply With Quote
  #2  
Old August 26th, 2003, 11:25 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
SELECT COUNT(*) from TABLE_NAME will return the total number of rows in the table.

Reply With Quote
  #3  
Old August 26th, 2003, 11:33 AM
artimador artimador is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 artimador User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool but how do I get that into a variable?

Reply With Quote
  #4  
Old August 26th, 2003, 11:49 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Huh ?

1) Create a Connection object to connect to your database

2) Createa a Recordset object that will hold the result of your Query

3) Buil your SQL Query(showed by karsh44)

4) Declare a variable that will hold the value of your recordset

5) Execute the SQL Query

6) Put the value of the recordset inside the variable you've define

7) Close recordset and connection object

8) Response.Write the variable


Hope this helps!
Sincerely

Vlince

Reply With Quote
  #5  
Old August 26th, 2003, 01:08 PM
artimador artimador is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 artimador User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here's What I have. I hate asking you all this and anoying you.

Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.ConnectionTimeout=60
MyConn.Open "DSN=files"

Set recordSet=Server.CreateObject("ADODB.Recordset")
recordSet.Open "SELECT COUNT(*) FROM rant", MyConn,1,2

Dim totalRants

totalRants = "What Goes Here?"

Reply With Quote
  #6  
Old August 26th, 2003, 01:28 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
<%
. . .
. .
.

Dim totalRants

If recordSet.EOF Then

Response.Write "No records found!"
Response.End

Else

totalRants = recordSet(0)

End If

recordSet.Close
Set recordSet = nothing

MyConn.Close
Set MyConn = nothing


'FOR DEBUG ONLY
Response.Write "-->" & totalRants & "<--<hr>"
Response.End
%>

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #7  
Old August 26th, 2003, 01:35 PM
artimador artimador is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 artimador User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you so much

the (0) part was what I was having trouble with... if it was a field I was working with it would have been simple.

Many thanks to the ASP Gods.

Reply With Quote
  #8  
Old August 26th, 2003, 01:41 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Well what you should've done is create an alias in your query something like:

"SELECT COUNT(*) as Total FROM rant"

Then you'd use it like this:
totalRants = recordSet("Total")

Hope this helps!
Sincerely

Vlince

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Help with blogger... Counting total rows in database table.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway