简体   繁体   English

PHP For 循环计算表中的行数,然后使用 MySQL 更新列值

[英]PHP For loop to count amount of rows in table and then update a column value using MySQL

In my form I have a table that is populated using MySQLi.在我的表单中,我有一个使用 MySQLi 填充的表。 Under the table there is a button that will call an AJAX script which will run my test.php file.在表格下方有一个按钮,它将调用一个 AJAX 脚本,该脚本将运行我的 test.php 文件。 This is where I need the for loop.这是我需要 for 循环的地方。 I have 2 values being echo'd.我有 2 个被回显的值。 Dotime (which needs to be updated in the database) and taskID which I need for the query. Dotime(需要在数据库中更新)和查询所需的 taskID。

jQuery code here: jQuery 代码在这里:

jQuery(document).ready(function(){

$('#UpdateTable').click(function()
{
    getdata();
}); 

function getdata()
{
    console.log($('#UpdateForm').serialize());

    $.ajax(
    {
    type: 'POST',
    url: 'test.php',
    data: $('#UpdateForm').serialize(),
    
    succes: function(data) 
    {
        alert(data);
    },
    error: function() 
    {
        alert("Something went wrong")
    }
    });
}

});

Test.php code:测试.php代码:

<?php 
$Time = $_POST['DoTime'];
$TaskID = $_POST['ID'];

echo $TaskID;
echo $Time;

?>

This is my table and the console output when I click update这是我的表和单击更新时的控制台输出

在此处输入图片说明

What I need to know is how do I build a For loop that will count my rows and then will update 1 value to the database using the data that shows up in the console.我需要知道的是如何构建一个 For 循环来计算我的行,然后使用控制台中显示的数据将 1 个值更新到数据库。

Note: I am very bad in PHP, I can do the basics but more advanced stuff like this I can't do properly.注意:我在 PHP 方面非常糟糕,我可以做基础知识,但是像这样的更高级的东西我不能正确地做。

Why count with a for loop?为什么用 for 循环计数? Can't you use the mysql count function? mysql的count函数不能用吗?

http://www.w3schools.com/sql/sql_func_count.asp http://www.w3schools.com/sql/sql_func_count.asp

(May i missunderstood your question... so sorry if this don't help.) (我是否可能误解了你的问题......如果这没有帮助,很抱歉。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM