Как отображать флажок при добавлении данных - PullRequest
0 голосов
/ 30 мая 2020

Я хотел бы создать список вопросов (с установленным флажком, если утверждение верное) в виде таблицы

TFquiz. php

<html>
    <head>
        <title>True/False Quiz</title>  
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>  
    </head>  

    <body>  
        <div> 
                <h1>True/False Quiz</h1<br/>
   <div ng-app="liveApp" ng-controller="liveController" ng-init="fetchData()">
                <div ng-show="success" >
                </div>

                <form name="testform" ng-submit="insertData()"><br>
                    <table width=50%>
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Question</th>
                                <th>True?</th>
                                <th>Modified By<th>
                                <th>Modified On</th>
                                <th>Update</th>
                                <th>Delete</th>
                            </tr>
                        </thead>
                        <tbody >
                            <tr>
                                <td align=center><input type="text" ng-model="addData.tf_id"  placeholder="No" ng-required="true" size="5"></td>
                                <td align=center><input type="text" ng-model="addData.tf_question"  placeholder="Enter Question" ng-required="true" size="100"></td>
                                <td align=center><input type="checkbox" ng-model="addData.tf_ans"  ng-checked="isChecked"></td>
                                <td align=center><button type="submit"  ng-disabled="testform.$invalid">Add</button></td>
                            </tr>
                            <tr ng-repeat="data in namesData" ng-include="getTemplate(data)"></tr>

                        </tbody>
                    </table>
                </form>
                <script type="text/ng-template" id="display">
                    <td align=center>{{data.tf_id}}</td>
                    <td align=center>{{data.tf_question}}</td>
                    <td align=center>{{data.tf_ans}}</td>
                    <td align=center><?php
                                     $connect = mysqli_connect("localhost", "root", "", "quiz");
                                     $sql = "SELECT * FROM lecturer INNER JOIN tfquiz ON lecturer.lecturer_id = tfquiz.lecturer_id";
                                     $result = mysqli_query($connect, $sql);
                                     if(mysqli_num_rows($result) > 0)
                                     {
                                         while($row = mysqli_fetch_array($result))
                                         {
                                             echo $row["lecturer_name"];
                                         }
                                     }
                                     ?></td>
                    <td align=center>{{data.tf_mod_date}}</td>
                    <td align=center><button type="button"  ng-click="showUpdate(data)">Update</button></td>
                    <td align=center><button type="button"  ng-click="deleteData(data.tf_id)">Delete</button></td>
                </script>
                <script type="text/ng-template" id="update">
                    <td><input type="text" ng-model="formData.tf_id"   /></td>
                    <td><input type="text" ng-model="formData.tf_question"  /></td>
                    <td>
                        <input type="hidden" ng-model="formData.data.tf_id" />
                        <button type="button"  ng-click="updateData()">Update</button>
                        <button type="button"  ng-click="reset()">Cancel</button>
                    </td>
                </script>         
   </div>  
  </div>
    </body>  
</html> 
<script>
var app = angular.module('liveApp', []);

app.controller('liveController', function($scope, $http){

    $scope.formData = {};
    $scope.addData = {};
    //$scope.success = false;

    $scope.getTemplate = function(data){
        if (data.tf_id === $scope.formData.tf_id)
        {
            return 'update';
        }
        else
        {
            return 'display';
        }
    };

    $scope.fetchData = function(){
        $http.get('selectTFquiz.php').success(function(data){
            $scope.namesData = data;
        });
    };

    $scope.insertData = function(){
        $http({
            method:"POST",
            url:"insertTFquiz.php",
            data:$scope.addData,
        }).success(function(data){
            //$scope.success = true;
            //$scope.successMessage = data.message;
            $scope.fetchData();
            $scope.addData = {};
        });
    };

    $scope.showUpdate = function(data) {
        $scope.formData = angular.copy(data);
    };

    $scope.updateData = function(){
        $http({
            method:"POST",
            url:"updateTFquiz.php",
            data:$scope.formData,
        }).success(function(data){
            //$scope.success = true;
            //$scope.successMessage = data.message;
            $scope.fetchData();
            $scope.formData = {};
        });
    };

    $scope.reset = function(){
        $scope.formData = {};
    };

//    $scope.closeMsg = function(){
//       $scope.success = false;
//   };

    $scope.deleteData = function(tf_id){
        //if(confirm("Are you sure you want to remove it?"))
        //{
            $http({
                method:"POST",
                url:"deleteTFquiz.php",
                data:{'tf_id':tf_id}
            }).success(function(data){
                //$scope.success = true;
                //$scope.successMessage = data.message;
                $scope.fetchData();
            }); 
        //}
    };

});
</script>

insertTFquiz. php

<?php  

//insertTFquiz.php

include('database_connection.php');

$message = '';

$form_data = json_decode(file_get_contents("php://input"));

$data = array(
 ':tf_id'  => $form_data->tf_id,
 ':tf_question'  => $form_data->tf_question
);

$query = "
 INSERT INTO tfquiz
 (tf_id, tf_question, tf_mod_date, lecturer_id) VALUES 
 (:tf_id, :tf_question, NOW(), 1234)
";

$statement = $connect->prepare($query);

if($statement->execute($data))
{
 $message = 'Data Inserted';
}

$output = array(
 'message' => $message
);

echo json_encode($output);

?>

описание изображения (я хочу установить флажок при добавлении вопроса)

Нет вопроса Верно? 1 ..... [/] Добавить btn

display

1 ..... [/] Кнопка обновления Кнопка удаления

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...