如何通过POST查询解析大数据

时间:2017-08-09 03:42:24

标签: javascript php ajax handsontable

我正在创建一个具有Excel功能的网页来创建Plan。为此我需要填写初始表单并单击提交按钮,然后使用ajax将表单提交到服务器端PHP脚本,该脚本将这些记录插入到Mysql表。 但问题是我只能使用POST查询传输1-2个表的记录,因为它有一个限制。在这种情况下我该怎么办?在不扩展POST查询限制的情况下还有其他方法吗? / p>

我的前端代码(.js)

</script>
buttons.save.addEventListener('click', function() {
    var r1 = hot.countRows() - hot.countEmptyRows() - 1;
    var c1 = hot.countCols()- 1 ;
    var data = String(hot.getData(0,0,r1,c1));
    data = data.replace(/,/g,'');
    document.getElementById('all_data').value= JSON.stringify(hot.getData(0,0,r1,c1));
    document.getElementById('colheaders').value=JSON.stringify(hot.getColHeader());
    console.log(hot.getInstance());
    var testplan_name = document.getElementById('feature_name').value;
    var product = document.getElementById('product').value;
    var release = document.getElementById('release').value;
    var pv_engg = document.getElementById('pv_engg').value;
    var pe_engg = document.getElementById('pe_engg').value;
    var rd_engg = document.getElementById('rd_engg').value;
    var tp_completion = document.getElementById('tp_completion').value;
    var at_completion = document.getElementById('at_completion').value;
    var all_headers = document.getElementById('colheaders').value;
    var all_data = document.getElementById('all_data').value;
    var maker = document.getElementById('maker').innerHTML;
    var datastring = 'testplan_name='+testplan_name+'&product='+product+'&release='+release+'&pv_engg='+pv_engg+'&pe_engg='+pe
_engg+'&rd_engg='+rd_engg+'&tp_completion='+tp_completion+'&at_completion='+at_completion+'&headers='+all_headers+'&all_data='
+all_data+'&maker='+maker;
   if(testplan_name=="" || pv_engg =='' || pe_engg== '' || rd_engg== '' || product=='' || release=='') {
      else if(data=="") {
      alert("For creating a testplan , you need to fill this table.");
    }
    else {

    alert(datastring);
     $.ajax({
     url :"save_create_pro.php",
     type :"POST",
     data : datastring,
     cache : false,
     success :function(result) {
       console.log(result);
       alert(result);
       alert("Form Submitted successfully");
     },
     error: function(jqXHR, textStatus, errorThrown) {
                   console.log(textStatus, errorThrown);
            }
     });
   }
   return false;

});
 });
</script>

我的后端php代码:

<?php
$dbh=mysql_connect('noiwebfarmo','abc','xyz');
if(! $dbh ) {
          die('Could not connect: ' . mysql_error());
}
$database=mysql_select_db('testmohit');
$testplan_name=$_POST['testplan_name'];
$product=$_POST['product'];
$release=$_POST['release'];
$pv_engg=$_POST['pe_engg'];
$pe_engg=$_POST['pe_engg'];
$rd_engg=$_POST['rd_engg'];
$tp_completion=$_POST['tp_completion'];
$at_completion=$_POST['at_completion'];
$maker=$_POST['maker'];
$headers=stripslashes($_POST['headers']);
$all_data = stripslashes($_POST['all_data']);# to remove \ before " that occur when parsed through ajax
$headers=preg_replace('/\["/','',$headers);
$headers=preg_replace('/"\]/','',$headers);
$headers=split('","',$headers);
for($j=0;$j<count($headers);$j++) {
      $headers[$j]= str_replace(' ','_',strtolower("$headers[$j]"));
}
$date=date('Y-m-d');

$all_data=preg_replace('/\[\["/','',$all_data);
$all_data=preg_replace('/"\]]/','',$all_data);
$rows_data=split('"\],\["',$all_data);
or($i=0;$i<count($rows_data);$i++) {
   $data[$i] = split('","',$rows_data[$i]);

}
$result = array();
foreach($data as $key => $val){
    $temp = array();
    foreach($val as $k => $v){
       $temp[$headers[$k]] = $v;
    }
    $result[] = $temp;
}
#print $all_data;
print count($result);
print_r($result);
for($i=0;$i < count($result);$i++) {
          $temp = $result[$i];
          $query = "INSERT INTO testplans (testplan_name,product,pro_release,percent_tpcompletion,percent_atcompletion,pv_engineer,rnd_engg,pe_engg,tc_name,cell_name,customer_name,flops,title,status,mfix_ccr,test_scenerio,expected_results,ccr_no,ccr_status,remarks,create_date,maker) VALUES ('$testplan_name','$product','$release','$tp_completion','$at_completion','$pv_engg','$rd_engg','$pe_engg','$temp[testcase_name]','$temp[cell_name]','$temp[customer]','$temp[flops]','$temp[title]','$temp[status]','$temp[mfix_ccr]','$temp[scenerio_brief_description]','$temp[expected_results]','$temp[ccr_no]','$temp[ccr_status]','$temp[remarks]','$date','$maker')";
          mysql_select_db('testmohit');
          $enter=mysql_query($query,$dbh);
          if(! $enter) {
           die('Could not enter data: ' . mysql_error());
          }
}

      # echo "$query Entered data successfully";
mysql_close($dbh);
?>

请提供插入大号的解决方案。不扩展查询字符串大小的handson表行。可以解决这个问题。

提前致谢。

0 个答案:

没有答案