You need a WHERE clause in your tracking query otherwise you will always get the latest result
how would I write a where statement for this?
Use the other fields to identify which user this is:
<cfquery NAME="tracking" datasource="#APPLICATION.dataSource#">
SELECT ID, REMOTE_ADDR, HTTP_USER_AGENT, SWidth, SHight, TRACK_DATE, PATH_INFO
WHERE REMOTE_ADDR = '#Trim(CGI.REMOTE_ADDR)#'
AND HTTP_USER_AGENT = '#Trim(CGI.HTTP_USER_AGENT)#'
ORDER BY ID
Alternatively you may be able to make use of session variables or cookies
That didn't work. Wouldn't I need to do something with the insert, to make sure the proper user had the proper info added to the db table? The query you attached the where statement to is just to view the records that were added by the insert function in the application.cfc
If you don't know how to write where statements, I have heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.
Having said that, you have bigger issues because your approach will result in duplicate db records, always a bad thing.
If your users are logged in then you can use their user names - although you'd still need to check in case of multiple log ins
What are you trying to do with the values? If the App.cfm file is reading the values each time then they can be read from there avoiding the database
So your saying I should have an insert query, and an update query to update existing records if a user comes back. I would need to set a coockie to do that and check to see if the cookie exists to see if they had been to the site before. Correct?
yes, I am weak on writting sql still, been working on it, I will look for that book.
In the mean time, how would I get the insert to do the right thing as this sits right now. I can add the cookie fucntion in later if that is the best approach for this. I was working on that feature anyway.
Do you need the info in the database?
what happens if you change the display page to just:
<cfoutput>#ScreenWidth# x #ScreenHeight#</cfoutput>
If this doesn't work then you may need to adjust the scope - hopefully someone else can correct any mistakes I make here - try either:
<cfoutput>#application.ScreenWidth# x #application.ScreenHeight#</cfoutput>
change the app.cfm file :
<!--- This grabs the users resolution --->
<CFSET session.ScreenWidth = "<script>document.write(screen.width);</script>">
<CFSET session.ScreenHeight = "<script>document.write(screen.height);</script>">
and the display page:
<cfoutput>#session.ScreenWidth# x #session.ScreenHeight#</cfoutput>
Yes, I am making a small tracking system, and I need to collect info on screen resolution. I did try the session.screenwidth and so on thinking it would narrow down the results by the actual session that is started. No, that didn't work either.I really think it has to do with what is being collected by the cfset and getting inserted into the DB is where the problem is.
so far those didn't work, and some I tried.BUT I did find this.
In my DB the actual resolution is not being collected, but this is being added to my db = <script>document.write(screen.width);</script>
so the cfset is not collecting the proper info. Any ideas?
You are starting to find the right track.
With computer programming, there is often more than one way to do things. To keep track of site visits, cookies are one way, but you relinquish control of your data because people can clear their cookies. I'd use a database entry myself.
You are also on the right track by wanting to update existing records with the latest data. This sort of logic will help you with that.
First run query to see if you have a record.
I like that idea better, I was also going to add like a "hit counter" so if it is updating the record, it adds +1 to a cell in the db so if they had 5 sessions, it would show 2 sessions and so on.
Right now, this is just the start of all that, I wanted to make sure I was collecting the info properly before I started playing with it. Don't know if that is the proper way to do things, but I like that approach. get the core built, then add on to it.
do you have any idea why my cfset is wrtting the actual script in my db and not the results from the cfset script?
I am making this more for marketing reasons, I know there are a lot out there, but, I kind of like making my own, I can make them do what I want and not have to figure out someone elses code to recode it. I learn more this way also.
If I was counting hits, I would have that in a separate table with one record per page request. More flexibility that way.