<?php 
        $answer = new Answer($conn);
        $allAnswer = json_decode($answer->getAllByQuestionId($questionid));
?>

<h6 class="by pad20"><span><?php print count($allAnswer) ?></span> Answer(s)</h6>
<div class="divider"></div>
<ul class="collection">
    <!--select all from answers table and loop them-->
    <?php
    if(count($allAnswer) > 0){
        for ($a = 0; $a < count($allAnswer); $a++){
            $content = $allAnswer[$a]->content;
            $id = $allAnswer[$a]->id;
            $question_id = $allAnswer[$a]->question_id;
            $answerUserId = $allAnswer[$a]->user_id;
    ?>
        <li class="collection-item">
            <!-- List of answers -->
            <?php 
                print $content;

                $answerUser = json_decode($user->getById($answerUserId));
                for ($u = 0; $u < count($answerUser); $u++){
                    print "<br /><span class='by font10'> By <span class='display__username'>".$answerUser[$u]->username . "</span></span>";
                }
            ?>
            <!-- <span>&bull;</span>
            <a href="#" id="edit_button" edit-btn="<?php print $id ?>"> edit</a> -->
            <div class="edit_holder row no-margin" id="editForm_<?php print $id ?>">
                <div class="col s12 l12">
                     <?php //require_once 'editForm.php' ?>
                </div>
            </div>
        </li>
    <?php
        }
    }else{
        print '
            There are no answers.
        ';
    }
    ?>
</ul>
<?php if (isset($_SESSION["signed_in"])){
?>
    <?php require_once 'answer-form.php' ?>
<?php } ?>

