Javascript 如何在JQuery POST PHP&;之后删除_POST中的空行;滑动分页

Javascript 如何在JQuery POST PHP&;之后删除_POST中的空行;滑动分页,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我用ajax Jquery写了一篇文章,效果很好,但结果如下: Array ( [facdatas] => Array ( [0] => Array ( [mbr_id] => 26 ) [1] => Array ( [nom] => Gautier Albert

我用ajax Jquery写了一篇文章,效果很好,但结果如下:

    Array
    (
    [facdatas] => Array
    (
        [0] => Array
            (
                [mbr_id] => 26
            )

        [1] => Array
            (
                [nom] => Gautier Albert
            )

        [2] => Array
            (
                [adresse] => Avenue du Devin du Village 51
            )

        [3] => Array
            (
                [ville] => 1406 Cronay
            )

        [4] => Array
            (
                [concerne] => TEST
            )

        [5] => Array
            (
                [totalFac] => 118.00
            )

    )

[ligneFac] => Array
    (
        [0] => Array
            (
                [designation] => Veste de training CPNS
            )

        [1] => Array
            (
                [unite] => pièces
            )

        [2] => Array
            (
                [quantite] => 1
            )

        [3] => Array
            (
                [prixUnite] => 49
            )

        [4] => Array
            (
                [taxe] => 0.00
            )

        [5] => Array
            (
                [totLine] => 49.00
            )

        [6] => Array
            (
                [designation] => Pantalon de training CPNS
            )

        [7] => Array
            (
                [unite] => pièces
            )

        [8] => Array
            (
                [quantite] => 1
            )

        [9] => Array
            (
                [prixUnite] => 69
            )

        [10] => Array
            (
                [taxe] => 0.00
            )

        [11] => Array
            (
                [totLine] => 69.00
            )

        [12] => Array
            (
                [designation] => 
            )

        [13] => Array
            (
                [unite] => 
            )

        [14] => Array
            (
                [quantite] => 
            )

        [15] => Array
            (
                [prixUnite] => 
            )

        [16] => Array
            (
                [taxe] => 0.00
            )

        [17] => Array
            (
                [totLine] => 0.00
            )
    ... ... ...
正如您可以从第[12]行中看到的,行是空的或数量为0.00,我尝试使用array_filter($\u POST['ligneFac'])删除这些行 但结果是一样的。 有没有办法删除第一列为空的所有行

谢谢你的帮助

以下是向表单中添加行的代码:

    $("#insLines").click(function()
{
    $("#matable tbody").append('<tr>'+
                            '<td width="10px">'+
                                '<img id="insArticle" src="../../images/icon_add.png" width="16" height="16">'+
                            '</td>'+
                            '<td width="250px">'+
                                '<input name="ligneFac[][designation]" type="text" class="facBig" />'+
                            '</td>'+
                           ' <td width="30">'+
                                '<input name="ligneFac[][unite]" type="text" class="facSmall" />'+
                            '</td>'+
                           ' <td width="30">'+
                                '<input name="ligneFac[][quantite]" type="text" class="facSmall" />'+
                            '</td>'+
                            '<td width="30">'+
                                '<input name="ligneFac[][prixUnite]" type="text" class="facSmall" value="" />'+
                            '</td>'+
                            '<td width="30">'+
                                '<input name="ligneFac[][taxe]" type="text" class="facSmall" value="" />'+
                            '</td>'+
                           ' <td width="30">'+
                                '<input name="ligneFac[][totLine]" type="text" class="facSmall" value="" />'+
                            '</td>'+
                       '</tr>');

                        iconeClicable();
});
$(“#插入行”)。单击(函数()
{
$(“#matable tbody”).append(“”+
''+
''+
''+
''+
''+
''+
' '+
''+
''+
' '+
''+
''+
''+
''+
''+
''+
''+
''+
' '+
''+
''+
'');
iconeClicable();
});

请尝试此演示代码:-

<?php    
    $arr=array();
    $arr['ligneFac'] = array("designation"=>"", "unite"=>"pièces", "quantite"=>"","taxe"=>"0.00");
     foreach($arr['ligneFac'] as $key =>$value)
     {
     if(!empty($value) && $value != "0.00"){
     $arr2['ligneFac'][$key]=$value;
    }
  }
  echo "<pre>";
  print_r($arr2);
  echo "</pre>";
 ?>

根据您发布的
print\r()
的输出,我假设您的值都是字符串。 在这种情况下,应采用以下方法:

foreach ($_POST['ligneFac'] as $i => $champs) {
    list($cle, $valeur) = each($champs);
    if ( ('taxe' !== $cle) && ( ('' === $valeur) || ('0.00' === $valeur) ) ) {
        unset($_POST['ligneFac'][$i]);
    }
}
(使用闭包需要PHP>=5.3.0。)

更新

$data = array(array('key1' => 10),array('key2' => 20,),array('key3' => ''));
$result = array_filter(array_map('array_filter', $data));

尝试此操作,这将删除没有值的条目

    <input name="ligneFac[][designation]" type="text" class="facBig" />

谢谢大家的帮助,这个问题现在已经解决了

首先,我表格的命名与此命名错误:

    <input name="ligneFac[1][designation]" type="text" class="facBig" />
并且没有使用“Francis Eytan Dorroct”更新代码的空行


希望这对任何人都有帮助…

您是如何创建此结构的?似乎不是很友好的代码这是来自$\u帖子的打印吗?如果是,就不要使用空字段,。为什么要费心删除它们呢?我试着这么做是对的:foreach($_POST[ligneFac])as$lignesFac如果(!empty($lignesFac['designation']){echo$lignesFac['designation'];echo$lignesFac['unite'];echo$lignesFac['quantite'];echo$lignesFac['prixUnite'];echo$lignesFac['taxes'];echo$lignesFac['totLine'.]结果是,只回显第一个键……请,如果你有自己问题的解决方案,将其作为答案发布,而不是编辑问题,否则你将无法达到问答模型的目的(未来用户将无法找出这个“问题”——不再是问题——试图解决的问题,使其毫无用处)。谢谢您的回答,这几乎就是我所需要的,只有一个值为“0.00”并且必须保留在数组中,这是用于taxe的。对于上一个代码,taxe键保留在所有行中,几乎与以前一样。如果我理解您的代码,那么在最后一行,您将删除整行[$i]。如果是,我不理解结果。是的,所有行。在某些情况下是否应将其移除?如果行中没有其他字段,例如?是,当第一个值(名称)为空,最后一个值(totLine)为“0.00”时,必须删除整行。一行是(名称-联合-prixUnite-taxe-totLine),只有taxe是“0.00”,如果名称不是空的,并且totLine>0,则必须保留在数组中。是否也要展平数组?将其转换为
数组([designation]=>[totLine]=>69.00[taxe]=>0.00)
    <input name="ligneFac[1][designation]" type="text" class="facBig" />
var nbr_tr = $('#fac_table tr').length;
var nbr_rows = nbr_tr -1; //to remove the header from calc.
newNum = nbr_rows + 1;

$("#matable tbody").append('<tr>'+
                        '<td width="10px">'+
                            '<img id="insArticle" src="../../images/icon_add.png" width="16" height="16">'+
                        '</td>'+
                        '<td width="250px">'+
                            '<input name="ligneFac['+newNum+'][designation]" type="text" class="facBig" />'+
                        '</td>'+
                       ' <td width="30">'+
                            '<input name="ligneFac['+newNum+'][unite]" type="text" class="facSmall" />'+
                        '</td>'+
                       ' <td width="30">'+
                            '<input name="ligneFac['+newNum+'][quantite]" type="text" class="facSmall" />'+
                        '</td>'+
                        '<td width="30">'+
                            '<input name="ligneFac['+newNum+'][prixUnite]" type="text" class="facSmall" value="" />'+
                        '</td>'+
                        '<td width="30">'+
                            '<input name="ligneFac['+newNum+'][taxe]" type="text" class="facSmall" value="" />'+
                        '</td>'+
                       ' <td width="30">'+
                            '<input name="ligneFac['+newNum+'][totLine]" type="text" class="facSmall" value="" />'+
                        '</td>'+
                   '</tr>');

iconeClicable();
});
    Array
(
[mbrDatas] => Array
(
    [1] => Array
        (
            [mbr_id] => 26
            [nom] => Gautier Albert
            [adresse] => Avenue du Devin du Village 51
            [ville] => 1406 Cronay
        )

)

[facdatas] => Array
(
    [1] => Array
        (
            [concerne] => TEST
            [totalFac] => 147.00
        )

)

[ligneFac] => Array
(
    [1] => Array
        (
            [designation] => Veste
            [unite] => pièces
            [quantite] => 1
            [prixUnite] => 98
            [taxe] => 0.00
            [totLine] => 98.00
        )

    [2] => Array
        (
            [designation] => Veste de training
            [unite] => pièces
            [quantite] => 1
            [prixUnite] => 49
            [taxe] => 0.00
            [totLine] => 49.00
        )

)

)
    foreach ($_POST['ligneFac'] as $i => $champs)
    {
    list($cle, $valeur) = each($champs);
    if ( ('taxe' !== $cle) && ( ('' === $valeur) || ('0.00' === $valeur)         ) )
    {
    unset($_POST['ligneFac'][$i]);
    }
    }