Wolf87
Wolf87

Reputation: 540

Get to the specific textarea and write data in it from database PHP?

I have questions which I'm reading form database and with while loop I show them all, but now I have answers on that questions also in database just in the other table. So, I need to put those answers into textarea's below every question, for questions without answers just to leave empty textarea. How can I know in the loop where to put specific answer, I mean how to tide questions-answers? Thanks.

here is the loop:

$j = 1;
    while($rowQuestion = $connector->fetchArray($resultUser)) {

        echo "
            <div class='question'>
                <h4>".$rowQuestion['wq_title']."</h4>
                <p>".$rowQuestion['wq_desc']."</p>
        ";
            $queryAnswer = "SELECT *
            FROM workshop_answers
            WHERE id_user='".$_GET['userid']."' AND q_comp='1' AND id_que='".$j."'";
            $resultAnswer = $connector->query($queryAnswer);
            $rowAnswer = $connector->fetchArray($resultAnswer);

        echo "
            <textarea readonly='readonly' id='".$j."'>".$rowAnswer['q_answer']."</textarea>

            <div class='ftr'>
                <a href='#top' class='pull-right'>Back to Top</a>
            </div>
            </div>
        ";
        $j++;
    }

Hey guys I made some modifications and now it works great. Thanks

Upvotes: 0

Views: 118

Answers (1)

sel
sel

Reputation: 4957

Use left outer join in your sql query to join the question table and answer table.

Upvotes: 1

Related Questions