Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2009, 04:26 PM
Authorized User
 
Join Date: Apr 2006
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Default Show only most recent record

I want to build a *very* simple form, one field. I want a person to be able to go in and update a single number. (example: '10 people are signed up out of 100 entries' - with 10 being the form number) I only want the most recent number to show up, not the previous numbers. (example: I don't want yesterday's 9 to show up once I put in today's 10)

I could set it up in a typical Do, While, Wend loop, but of course that isn't going to work. Is there a simple, quick way to pull only the most recent number and display only that number from a database?

I plan on using an 'ID' unique field. Also, I plan on using 'SubmitDate' to show the date of each entry. The only other field I plan on is 'DayCount'.
 
Old April 22nd, 2009, 05:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Scratching my head...

Why should you NEED to "update a single number"? Why can't/shouldn't you just get that number from data that's already *IN* the database??

And if there is only a "single number", then why is there such a thing as "most recent number"??

In any case, you should never update something by hand that can, instead, be derived from data in the DB.

Can you show us your DB schema?? All the relevant fields of all the relevant tables??

Conceptually, this is trivial, but I am really afraid there is something badly messed up with the DB design.

You could use SQL to get the most recent record:
Code:
SELECT ID, SubmitDate, DayCount
FROM table
WHERE SubmitDate = ( SELECT MAX(SubmitDate) FROM table )
Or, if the ID field is an autonumber field,
Code:
SELECT ID, SubmitDate, DayCount
FROM table
WHERE ID = ( SELECT MAX(ID) FROM table )
Or, depending on what DB your are using (yes, it matters)
Code:
SELECT TOP 1 ID, SubmitDate, DayCount
FROM table
ORDER BY ID DESC
or
Code:
SELECT TOP 1 ID, SubmitDate, DayCount
FROM table
ORDER BY SubmitDate DESC
or or or ...

But it's not clear to me why you should be updating DayCount manually, at all.
 
Old April 22nd, 2009, 06:07 PM
Authorized User
 
Join Date: Apr 2006
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Well, I haven't started the programming as of yet, cause I knew there was a way to do what I wanted. But, here's my thoughts.

Table columns: ID(unique) - DayCount - SubmitDate

The page itself would be text:

"We have 100 spots open - Right now ## have signed up!"

I want someone, other than me, to be able to go in each day (maybe several times a day??) and update the ##. Didn't want them to have to 'Delete' yesterday, or do any other finagling, just type in the ## and hit submit. The page then would automatically update with the new ##.

So, the database would actually have a lot of numbers in it by the time it's run it's life. That is where the 'most recent' comes into play. Just wanted to update the page with the number they just typed in. I know how to display all the records, but this just picking one has me stumped.

Thanks!
 
Old April 22nd, 2009, 06:20 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Nope. Do NOT do it that way!

Let's say you have a table like this:
Code:
Table: Signups
   ID int autonumber primary key 
   name text
   email text
   whenSignedUp datetime (and records *both* date and time!)
   ... other fields ...
So now all you do is:
Code:
<%
CONST SLOTS = 100
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

SQL = "SELECT COUNT(*) FROM Signups"
Set RS = conn.Execute( SQL )
count = 0
If Not RS.EOF Then count = RS(0)
RS.Close
%>
We have <%=SLOTS%> slots available.<br/>
<%=count%> have already signed up.<br/>
<% If count >= SLOTS Then %>
    Sorry, there are no more slots available.
<% Else %>
    There are still <%=(SLOTS-count)%> slots available.
<% End If %>
...
Now you have the number of signups CORRECT TO THE MILLISECOND!
 
Old April 22nd, 2009, 06:25 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

And by the way, you could *ALSO* get the count at any time in the past, if you had reason to do so.

For example, you could find out how many had signed up a week ago via
Code:
SELECT COUNT(*) FROM Signups WHERE whenSignedUp < DATE()-6
(That's for Access DB; slight differences for other DBs.)

Or you could find out how many signed up yesterday, say:
Code:
SELECT COUNT(*) FROM Signups WHERE DATEVALUE(whenSignedUp) = DATE()-1
(Again, that's for Access. Ask if you want it for a different DB.)

Many many variations on that theme possible.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show more recent forums topics on de master kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 December 12th, 2006 11:52 AM
WHy does it show 1 record per page instead of 10? gilgalbiblewheel Classic ASP Databases 2 April 27th, 2005 11:03 AM
show one record if there are duplication yylee Access 1 January 9th, 2005 05:57 AM
show the record number yami56 Access 9 April 5th, 2004 08:35 PM
Accessing most recent record? prabodh_mishra SQL Server 2000 4 September 24th, 2003 09:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.