I have a page where Fire Safety Training Components are dynamically generated from a php foreach loop. I also give the option to the user to comment on the training component, and administrator can respond to the comment. In essence creating a discussion for a particular Fire Safety training component. I am still working on localhost to develop the site. What I would like to accomplish is insert the conversation in a jquery accordion underneath the training component so the user has the choice to see the discussion or not.
the problem that I am having is I can only make the first result work. I figured out this was because the div id needs to be unique for each loop. I was wondering if someone can help me increment the javascript function and div result?
here is the code I use to produce the data:
$(function() {
$( "#Accordion2" ).accordion({
active: false,
collapsible: true,
});
});
</script>
</head>
<body>
<div class="gridContainer clearfix">
<nav id="nav"> <?php include ("includes/nav_employee.php");?> </nav>
<div id="main">
<div class="pageTitle">
<?php
include ("includes/title.php");
?>
</div pageTitle>
<hr>
<?php
if(Session::exists('FS')){
echo '<div class="message"><span class="flashT">MESSAGE:</span> <br /><span class="flash">' . Session::flash('FS') . '</span></div><br />';
}
if(Session::exists('FSnoAss')){
echo '<div class="message"><span class="flashT">MESSAGE:</span> <br /><span class="flash">' . Session::flash('FSnoAss') . '</span></div><br />';
}
if(Session::exists('response')){
echo '<div class="message"><span class="flashT">MESSAGE:</span> <br /><span class="flash">' . Session::flash('response') . '</span></div><br />';
}
if(Session::exists('home')){
echo '<div class="message"><span class="flashT">MESSAGE:</span> <br /><span class="flash">' . Session::flash('home') . '</span></div><br />';
}
if(Session::exists('CommentDeleted')){
echo '<div class="message"><span class="flashT">MESSAGE:</span> <br /><span class="flash">' . Session::flash('CommentDeleted') . '</span></div><br />';
}
?>
<div class="stretch">
<h3 class="output">
The following is a collection of Fire Safety Training Component that were written by the Fire/Safety Director of a particular Site Location. Every Associates working at this particular site should make themselves familiar with the content of this page.
</h3><br /> Each Site requires a Fire/Safety Director. Please send us your request if you would like to receive "Administrator priviledges." Administrator can produce fire safety reports and conduct fire drills and write site specific fire safety training component. Send an email here with your request to receive <a href="contact.php">Admin priviledges.</a> <br /><br /></h3>
</div>
<?php
//pulls out all current component in a list
if(isset($_GET['id'])){
echo'';
}else{
echo '<div class="output"><h3>Already existing Fire Safety Training Components.</h3><p style="text:small;">Click to navigate to the desired Fire Safety Component</p>';
$currentComponents = DB::getInstance()->query("SELECT * FROM fscomponents WHERE siteId=$siteId ORDER BY ComponentTitle ASC");
if($currentComponents->count()){
echo'<ul>';
foreach($currentComponents->results() as $cc){
echo '<li class="li"><a href="#'.$cc->componentTitle.'">'.$cc->componentTitle.'</a></li>';
}
echo '</ul>';
}
echo '</div>';//outputHeading
}
?>
<?php
if(isset($_GET['id'])){
$id=$_GET['id'];
//this check to see if the request was made to lookup one component and returns the one component that was selected in a nother page
$FSComponents = DB::getInstance()->get('fscomponents', array( 'id', '=', $id));
}else{
//this return all components
$FSComponents = DB::getInstance()->query("SELECT * FROM fscomponents WHERE siteId=$siteId ORDER BY ComponentTitle ASC");
}
foreach($FSComponents->results() as $rows){
echo '<br /><div><a name="'.$rows->componentTitle.'"><span class="outputHeading">'.$rows->componentTitle.'</span> </a></div>';
echo '<div class="wrapper">'; ///////////
echo '<div class="titleNav">
<ul>';
if($user->data()->groupId <2){
echo'';
}else{
echo'<li class="li"> <a href="firesafetycomponents_update.php?id=' . escape($rows->id) . '">Update Component</a></li>';
}
echo '<li class="li"><a href="firesafetycomponent_comment.php?id=' . escape($rows->id) . '">Add a Comment</a></li>';
echo '<li class="li"><a href="#top">Top of the page</a></li>
</ul>
</div>';
echo '<div class="stretchColorC">'. $rows->FSComponent. '</div><br />';
echo'<div id="Accordion2">';
echo '<h3>Discussion</h3>';
echo '<div>';
//comment start
$comments = DB::getInstance()->query("SELECT * FROM fscomponentcomments WHERE FSComponentId = $rows->id");
if($comments->count())
foreach($comments->results() as $comment){
$date= date ("F d, Y",strtotime($comment->FSCCCreatedDate));
echo '<div class="compoComment"><div class="componentTitle">';
$createdBy= DB::getInstance()->query("SELECT id,firstname, lastname FROM associates WHERE id=$comment->FSCCCreatedBy");
if($createdBy->count()){
foreach($createdBy->results() as $name){
echo '<a href="associate_details.php?user=' .escape($name->id).'">'.$name->firstname .' ' . $name->lastname.'</a> Commented on '.$date;
if(!$user->isLoggedIn() || $user->data()->groupId <2){
echo '</div>';
}else{
echo ' <a href="firesafetycomponent_comment_response.php?id=' . escape($comment->id) . '">Respond inside this tread</a> ' ;
echo ' <a href="firesafetycomponent_comment_delete.php?id=' . escape($comment->id) . '">Delete this comment</a><br /></div><br />' ;
}
//menu starts here for response
echo '<div>';//div to wrap comment and question together
echo '<div class="componentComment">'.$comment->FSCComment.'</div></div>';
//response start///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$responses = DB::getInstance()->query("SELECT * FROM fsccresponses WHERE FSCCommentId = $comment->id");
if($responses->count()){
foreach($responses->results() as $response){
$resDate = date ("F d, Y",strtotime($response->FSCCRDate));
echo '<div><div class="componentResponse">';
$resCreatedBy = DB::getInstance()->query("SELECT id,firstname, lastname FROM associates WHERE id=$response->createdBy");
if($resCreatedBy->count()){
foreach($resCreatedBy->results() as $resName){
echo '<a href="associate_details.php?user=' .escape($resName->id).'">'.$resName->firstname .' ' . $resName->lastname.'</a> Responded on '.$resDate.'<br /></div><br />' ;
echo '<div class="componentResComment">'.$response->FSCCResponse.'</div></div>';
}//foreach $resCreatedBy
}//if resCreatedBy
}//foreach $responses
}//if $responses
echo'</div>';//div to wrap comment and response together
}
}
}
echo '</div><br />';//wrapper
echo '</div>';//accordion
echo '</div>';//accordion
}
?>