【问题标题】:how to break array into chunks and post them to mysql? [closed]如何将数组分成块并将它们发布到mysql? [关闭]
【发布时间】:2013-07-23 12:51:40
【问题描述】:

我有使用价值

var data = [];

  $('#customers > tbody  > tr').each(function(){


    var rollno=$(this).find('td:nth-child(2)').text();
    var marks=$(this).find('td:nth-child(4)').find('input').val();


      if(marks=='' ||subjcode=='')
     {
         alert('marks is null')
     }
     else
     {
         data.push(rollno);
         data.push(subjcode);
         data.push(marks);
         //data.push(teacherid);
     }

  })//each

实际上我得到了一个包含多个值的数组,但我想将它们分成 3 个整数块并将它们发布到数据库中......该怎么办?

我可以使用 foreach 发布它们吗? 如果是,那怎么办? 如果没有,那么其他方法是什么?

【问题讨论】:

  • 你能更准确地说明你想做什么吗?
  • 这个question可以帮助你
  • $.ajax$.postarray_chunk 浮现在脑海中,它们是 IMO 的描述性函数名称
  • 不要将值推送到数组中 - 只需将它们以 3 个一组的形式发布
  • 谢谢你,先生...thanx a ton...it help....

标签: php jquery mysql


【解决方案1】:

你的意思是这样的吗?

$("#customers > tbody  > tr").each(function(){
    var rollno = $(this).find("td:nth-child(2)").text();
    var subjcode $(this).find("td:nth-child(3)").text();
    var marks = $(this).find("td:nth-child(4)").find("input").val();

    if (marks == "" || subjcode == "") {
        console.log("marks is null")
    } else {
        $.ajax({
            url: "your-data-handler.php",
            type: "POST",
            data: {
                rollno: rollno,
                subjcode: subjcode,
                marks: marks
            },
            success: function() {
                // success handler
            },
            error: function() {
                // error handler
            }
        });
    }
});

我猜到了subjcode 的值,但这是一个将数据推送到可以处理它并将其保存到数据库的 php 文件的示例。

我真的建议一次发送所有数据。许多请求会产生大量开销,并且会减慢用户和 Web 服务器的进程。

【讨论】:

    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 2019-06-02
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多