Results 1 to 5 of 5

Thread: Counting number of expansions i ddAcordion

  1. #1
    Join Date
    Mar 2010
    Location
    Sweden
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Counting number of expansions i ddAcordion

    1) Script Title: ddAcordion 1.7

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...daccordion.htm

    3) Describe problem: I'm using ddAcordion in a FAQ-page using PHP. I want to count all expanded clicks and save the number of cklicks i the database in the php-script. In that way I can sort the questions with the most used question on the top.

    The counter must be updated for every singel expansion and saved in the database.

    Is this possible?

  2. #2
    Join Date
    Aug 2004
    Posts
    9,918
    Thanks
    3
    Thanked 969 Times in 957 Posts
    Blog Entries
    15

    Default

    So if a user expands and contracts the same header 10 times, that should be counted as 10 clicks?
    DD Admin

  3. #3
    Join Date
    Mar 2010
    Location
    Sweden
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, that's what I want.

  4. #4
    Join Date
    Aug 2004
    Posts
    9,918
    Thanks
    3
    Thanked 969 Times in 957 Posts
    Blog Entries
    15

    Default

    Well the basic idea of counting the number of times a content has been expanded by the user isn't hard, thanks to the script's onopenclose() event handler. The below code in red for example will alert the number of times a particular header has been expanded by the user each time he/she performs this action:

    Code:
    //Initialize 2nd demo:
    ddaccordion.init({
    	headerclass: "technology", //Shared CSS class name of headers group
    	contentclass: "thelanguage", //Shared CSS class name of contents group
    	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
    	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
    	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
    	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
    	animatedefault: false, //Should contents open by default be animated into view?
    	persiststate: false, //persist state of opened contents within browser session?
    	toggleclass: ["closedlanguage", "openlanguage"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    	togglehtml: ["prefix", "<img src='http://i13.tinypic.com/80mxwlz.gif' style='width:13px; height:13px' /> ", "<img src='http://i18.tinypic.com/6tpc4td.gif' style='width:13px; height:13px' /> "], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    	oninit:function(expandedindices){ //custom code to run when headers have initalized
    		//do nothing
    	},
    	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
    		if (isuseractivated==true && state=="block"){
    			header._count=(typeof header._count=="undefined")? 1 : header._count+1
    			alert(header._count)
    		}
    	}
    })
    Now, what's left is the harder part, which is to transmit this information to a database each time. The specifics really depends on how your database is set up, its fields etc. In general the idea is to use Ajax to send the value of header._count and add it to the corresponding header's entry in your database. This might be something more suited for the Paid Work Offers forum.
    DD Admin

  5. #5
    Join Date
    Mar 2010
    Location
    Sweden
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help so far! I'm not so familiar with javascript so I have to try to find a way to read the count value in the php-code. To put it into the database is no problem. My problem now is the comunication between javascript and php.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •