View Full Version : Submit Button Counter / Chart
05-21-2009, 11:36 PM
New here to CodingForums thanks for having me. Hello All!
I read an article on this forum that was about a counter that tracked button clicks. The problem is it's not quite what I was looking for so I'm posting to see if anyone can help on this matter.
If you need additional info let me know. Thanks for any help anyone can provide me with. :thumbsup:
05-21-2009, 11:45 PM
Don't see any way to do this without *some* server-side capabilities.
NOTE: *IF* you have server side capabilities on some *other* server, you could use AJAX to have JS code from HTML pages on this server both get the table and update it on the server-capable server.
05-22-2009, 05:56 PM
If I could manage *some* server side capabilitities what would you suggest?
Thanks BTW for the response.
05-22-2009, 09:57 PM
Really doesn't matter. Any of the common technologies are more than adequate for this.
You should probably use a simple database, unless you are talking about only a handful of people (in which case you could get away with storing the data in a text file).
You aren't talking about more than a couple of dozen lines of code, in JSP/PHP/ASP, along with a simple database (say Access or MySQL or even a ".csv" file).
05-22-2009, 11:24 PM
Correct very small. A txt file would be sufficient. This site is just a portal for submitting those forms I spoke of. I would probably log the values of the counter at the end of each month and start over.
Could you help me with a generalization of how to do it say using .asp to get me started? Once I figure out how to get started I "think" I can get going on it. I just really don't have a clue where to start. Or a basic concept of how to get the onclick to log into a txt file then to display it somewhere on the main page.
05-23-2009, 12:02 AM
If using ASP, it's about as easy to use an Access DB as it is to use a file, but okay...
We will say that the file format is this:
name : count
with each person on a separate line.
So the file might look like:
And anybody who has not submitted a form doesn't even appear in the file.
We will put the file into a directory named "data" that is under the root directory. We'll put the code in the root directory. We will assume that you will invoke the page by hitting a URL of the form http://www.yoursite.com/countDownloads.asp?name=John+Doe
name = Request("name")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set infile = FSO.OpenTextFile( Server.MapPath("data/downloads.txt") )
lines = infile.ReadAll ' reads entire text file into memory
lines = Split( lines, vbNewLine ) ' break text into an array of lines
done = False
For i = 0 To UBound(lines)
temp = Split( lines(i), ":" )
If LCase(name) = LCase(temp(0)) Then
' aha! this person already in the file...change his/her count:
temp(1) = CINT( temp(1) ) + 1
' put the line back in place:
lines(i) = Join( temp, ":" )
done = True
Exit For ' and we are done
If Not done Then
' that name not found in the file, so add a line:
ReDim Preserve lines( UBound(lines) + 1 ) ' bump size by 1
lines( UBound(lines) ) = name & ":1" ' give this person one download
' true says overwrite existing file:
Set outfile = FSO.CreateTextFile( Server.MapPath("data/downloads.txt"), True )
outfile.Write Join( lines, vbNewLine ) ' write out all the lines
outfile.WriteLine "" ' with a terminating line break
Yeah, would actually be slightly shorter to use a database.
05-23-2009, 12:12 AM
Just for grins, here it is using an Access DB, also in the "data" directory:
name = Trim(Request("name"))
If name = "" Then Response.End ' no name? do nothing
name = Replace( name, "'", "''" )
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("./data/downloads.mdb")
SQL = "UPDATE userDownloads SET count=count + 1 WHERE name='" & name & "'"
howmany = -1
conn.Execute SQL, howmany
If howmany <= 0 Then
SQL = "INSERT INTO userDownloads (name,count) VALUES('" & name & "',1)"
05-23-2009, 02:38 PM
Im going to sit down this weekend and play around with that. Thanks!
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.