doddsey_65 Posted October 20, 2010 Share Posted October 20, 2010 Im working with the animatedcollapse.js file which collapses divs. I need to collapse divs with the id's 1,2,3,4. Simple enough. However they wont always be 1,2,3,4 as these are the ids (forum_id) pulled from the database. the animatedcollapse.js script requires the names of the divs to be entered like so: <a href=\"javascript:animatedcollapse.show(['1','2','3','4'])\"> but like i said it won't always be 1,2,3,4 so how can i pull the id's and add them to that href? i was thinking an array but ive never worked with them before so i cant get it to work. I need to pull all of the forum_id's where parent_id = 1 and then add the id's to the href. Link to comment https://forums.phpfreaks.com/topic/216366-animated-collapse-with-variables/ Share on other sites More sharing options...
Buddski Posted October 20, 2010 Share Posted October 20, 2010 If I understand correctly something like this might work. $sql = "SELECT `forum_id` FROM `forums` WHERE `parent_id` = 1"; $sql_query = mysql_query($sql); $ids = array(); while ($data = mysql_fetch_assoc($sql_query)) { $ids[] = $data['forum_id']; } if (!empty($ids)) { echo '<a href="javascript:animatedcollapse.show([\''.join("','",$ids).'\'])">'; } Link to comment https://forums.phpfreaks.com/topic/216366-animated-collapse-with-variables/#findComment-1124347 Share on other sites More sharing options...
doddsey_65 Posted October 20, 2010 Author Share Posted October 20, 2010 thanks it works perfectly. Link to comment https://forums.phpfreaks.com/topic/216366-animated-collapse-with-variables/#findComment-1124355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.