C
C
coldunox2018-06-14 21:41:13
PHP
coldunox, 2018-06-14 21:41:13

How to organize a cycle in this case?

I have a list of tests
5b22b50e1b9d9180553882.png
When I click on it, I can see the content of the question
5b22b5304ed00320009236.png
I have a link between a test table and a question
5b22b5b49669c174908005.png
table Table

<table class="table table-bordered table-hover table-striped">
 <thead>
    <tr>
        <th>Номер</th>
        <th>Название</th>
    </tr>
</thead>
<tbody>
   <?php
        foreach ($pageData['tests'] as $key => $value) { ?>
            <tr>
                <td><?php echo $value['id']; ?></td>
                <td><a data-ng-click="getInfoByTaskId(<?php echo $value['id']; ?>)" href="<?php echo $value['id']; ?>" ><?php 
                   echo $value['name']; ?></a></td>
            </tr>
        <?php } ?>
</tbody>
</table>

I make a selection by condition
public function getTaskById($id){
        $result = array();
        $sql = "SELECT *
                FROM questions 
                WHERE id_tests =:id";
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(":id", $id, PDO::PARAM_INT);
        $stmt->execute();
        $result = $stmt->fetch(PDO::FETCH_ASSOC);
        return $result;
        
    }

The form itself
<form class="form-horizontal"  name="taskInfo" data-ng-submit="saveTask()">
    <input type="hidden" id="id" data-ng-model="id">
    <legend>Редактирование заданий</legend>
        
     <div class="form-group">
        <label for="category" class="col-sm-3">Текст вопроса</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="text_ans" id="text_ans" class="form-control">
        </div>
    </div>

    <div class="form-group">
        <label for="category" class="col-sm-3">Вариант ответа 1</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="variant_a" id="variant_a" class="form-control">
        </div>
    </div>
    
    <div class="form-group">
        <label for="content" class="col-sm-3">Вариант ответа 2</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="variant_b" id="variant_b" class="form-control">
        </div>
    </div>
    <div class="form-group">
        <label for="category" class="col-sm-3">Вариант ответа 3</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="variant_c" id="variant_c" class="form-control">
        </div>
    </div>
        
    <div class="form-group">
        <label for="content" class="col-sm-3">Вариант ответа 4</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="variant_d" id="variant_d" class="form-control">
        </div>
    </div>

        
    <div class="form-group">
        <label for="content" class="col-sm-3">Верный ответ</label>
        <div class="col-sm-9">
            <input type="text" data-ng-model="id_answers" id="id_answers" class="form-control">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <button class="btn btn-default">Сохранить</button>
             <button class="btn btn-danger" type="button" data-ng-click="deleteTask(taskId)">Удалить</button>       
        </div>
    </div>
</form>

How to organize a cycle so that the editing window is for all questions of this test
==========================

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question