View Full Version : Counting number of expansions i ddAcordion

03-12-2010, 12:54 PM
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?

03-13-2010, 02:14 AM
So if a user expands and contracts the same header 10 times, that should be counted as 10 clicks?

03-15-2010, 09:06 AM
Yes, that's what I want.

03-16-2010, 09:59 AM
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 (http://www.dynamicdrive.com/dynamicindex17/ddaccordion_suppliment2.htm). 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:

//Initialize 2nd demo:
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

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 (http://www.dynamicdrive.com/forums/forumdisplay.php?f=29).

03-16-2010, 02:54 PM
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.