Skip to main content
Participant
January 30, 2007
Question

onLoad page > update row

  • January 30, 2007
  • 2 replies
  • 310 views
Hi CF Forum,

I'm basically trying to create a most-viewed scheme for my dynamic pages.
I thought on doing a onLoad function that triggers a cfupdate (adding 1 to the "viewed" column).

I'm imagining I would have to do this with a javascript funtion, but I'm not sure what code to use.
Can anyone help me on this?

Thanks in advance.

Best,

Manuel
--
    This topic has been closed for replies.

    2 replies

    _mslima_Author
    Participant
    January 31, 2007
    Thanks for the very detailed answer Dan...

    Fortunately I was able to solve it faster than I thought.
    Since this might help other people with similar questions, this is what I did.

    <!--- This basically adds 1 to the existing value on my VIEWS column --->
    <CFSET current_views = #query_name1.views# + 1>

    And then I just used this query:
    <cfquery DATASOURCE="dbsource" NAME="query_name" >
    UPDATE table_name
    SET views = #current_views#
    WHERE id = #URL.id#
    </cfquery>>

    An easy way to grab your page views.
    All for the purpose of filtering content by "Most Viewed" elements.

    Inspiring
    January 31, 2007
    quote:

    Originally posted by: _mslima_
    Thanks for the very detailed answer Dan...


    no need to be sarcastic, _mslima_. you did not really provide much details about your problem in the first place, hence it was hard to give you a detailed solution...

    congrats on figuring it out yourself. however, i can see potential problems with your code... like when a number of users requests same page at the same time... your code may not put the correct number in the db without some scoping/locking/transactions...

    but if your site only gets a few visitors a day and/or you do not need number of pageviews to be 100% accurate, it should not be a problem
    Inspiring
    January 31, 2007
    You do it with cold fusion, not javascript.