duan010167787 2015-02-11 10:00
浏览 95

在while循环php中更新数据库记录

I am trying to develop a simple page in php to update attendance days.I have set the query to display the records from db and added a check box with data displayed from db.I want to update the specific record of db on which check box is checked.i want to update the the attendance column with 1 to existing value.for this i just tried written code to display the data from db and added a check box but dnt know to update the record where check box is checked on submit button.here is my initial code.any one help

<?php
require_once("../db/db_connect.php");
$db = new DB_CONNECT();
$sql = "SELECT cv_id, cd_id, cv_fomfeeback FROM candidateverification;";
$res = pg_query($sql) or die ($sql);
    // output data of each row
    while($row = pg_fetch_row($res)){
        echo "cd id: " . $row[0]. "  cv id: " . $row[1]. "  atn: " . $row[2]. "<input type='checkbox' value='1'/> <br>";
    }
 ?>
<html lang="en">

<head>
<body>    
    <input type="button" action="update" value="Submit"/>
</body>

</html>

I want to update cv_fomfeeback column with +1 if check box is checked.

  • 写回答

1条回答 默认 最新

  • dsjgk330337 2015-02-11 11:06
    关注

    First you need to name your checkbox. You must do this in a way, so that you get all the checkboxes (-> array) and know the row id of the checkes boxes (-> associative array).

    Your checkbox could look like this:

    echo "<input type=\"checkbox" name=\"boxes[{$row[0]}]\" value=\"1\">";
    

    On the page that is called after submit has been done (see the comment of @TheNAkos) you will find all checked boxes in the associative array accessible via

    $_POST["boxes"]
    

    From there you need to loop through the array and update the rows accordingly.

    I will not post a complete example, but those hints should help you find the solution by yourself.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答