PDA

View Full Version : Switch Content Script: modify default expanded array



majocmatt
03-19-2007, 11:50 PM
1) Script Title:
Switch Content Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm

3) Describe problem:

When you create a new switchcontent object, you have to put the instance number(s) in the defaultExpanded method. I was wondering if anyone has successfully modified this for database driven dynamic content.

For instance, I would like those numbers to instead be unique ID's instead of array instances. Is this easily adaptable? I don't know JS

majocmatt
03-20-2007, 12:21 AM
I actually came up with a solution using PHP.

I pulled out the unique ID's from a mysql database that I needed to work with using PHP, put them into an array, then used the array_keys() PHP function to reset the array's key numbers.

So my uniques went from [12],[23],[43] to [0],[1],[2]

I then used PHP's implode() function to turn the array into a comma delimited string, and stored it into a new variable.

Finally, I echoed that variable within the javascript in the defaultExpanded method parenthesis.

Since my SQL query brought the records out in a certain order, the order of the newly created variable that stores the comma delimited string stayed the same.

You just have to start a new variable just for the switch content script, and not use the new ones for the actual data retrieval.