duandongji2231 2015-11-03 17:55
浏览 45

更新复选框上的单个MySQL记录单击AngularJS

I am creating a golf tournament check-in app and want to be able to update an individual record in the MySQL database when a checkbox is clicked. So, when someone checks in they click the checkbox by their name and I want it to then update the database record of that person (the checked in column set to 1 for the specific id of the person) so that others can see that the person is checked in almost immediately.

I am not sure how to get both the id and the checkedin value to update only the affected record when a checkbox is clicked.

app.js

var checkinApp = angular.module('checkinApp', []);

checkinApp.controller('checkinController', function($scope, $http, $location, $anchorScroll) {

$http.get('lib/api.php').success(function(data) {
    $scope.checkindata = data;
});


$scope.processForm = function(checkedindata) {
    $http.post('lib/process.php', { gid : checkedindata.gid, checkedin : checkedindata.checkedin })
      .then(function(data) {
        console.log(data);
       })
  };

});

HTML/Output

<table class="table table-striped table-responsive">
    <tbody>
                <tr>
                    <th>Checked In</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Company</th>
                    <th>Starting Hole</th>
                </tr>
                <tr ng-repeat="item in checkindata">
                    <td><input type="checkbox" name="checkedin" ng-model='checkedin' ng-change='processForm(checkedindata)' ng-checked="item.checkedin == 1"/></td>
                    <td>{{item.fname}}</td>
                    <td>{{item.lname}}</td>
                    <td>{{item.cname}}</td>
                    <td>{{item.hole}}</td>
                </tr>
    </tbody>
</table>

process.php

<?php
require_once('../includes/cred.php');


$checkedin = $_POST['checkedin'];

$sth = $dbh->prepare("UPDATE golfers SET checkedin=$checkedin");
$sth->execute();

DB Table DB Table

Output Output

  • 写回答

1条回答 默认 最新

  • dongwoqin7034 2015-11-03 17:58
    关注

    Simply replace ng-change='processForm(checkedindata)'

    by ng-change='processForm(item)'

    and in your PHP code do something like :

    $sth = $dbh->prepare("UPDATE golfers SET checkedin=$checkedin->checkedin WHERE gid=$checkedin->gid");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端