Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中使用格式化数字的数据表排序_Php_Datatables - Fatal编程技术网

PHP中使用格式化数字的数据表排序

PHP中使用格式化数字的数据表排序,php,datatables,Php,Datatables,我有个问题,找不到任何解决办法。 我有一个数据库,从那里我选择了很多信息,然后计算这些数据 $table->td( array($row->mailing_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""), array($row->mailing_unique_id, "width=

我有个问题,找不到任何解决办法。 我有一个数据库,从那里我选择了很多信息,然后计算这些数据

 $table->td(              
            array($row->mailing_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array($row->mailing_unique_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array($row->mailing_name, "width=\"300\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array($row->campaign_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array($row->segment_name, "width=\"100\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""), 
            array($row->total_sent, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@$viewSum[$row->mailing_unique_id], "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@number_format((@$viewSum[$row->mailing_unique_id] * 100)/$row->total_sent,  2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(number_format(@$leadssum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@number_format((@$leadssum[$row->mailing_unique_id]*100)/$row->total_sent,2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@number_format((@$leadssum[$row->mailing_unique_id] * 100)/@$viewSum[$row->mailing_unique_id], 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(number_format(@$crossviewSum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(number_format(@$crossleadsSum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@number_format((@$crossleadsSum[$row->mailing_unique_id] * 100)/@$crossviewSum[$row->mailing_unique_id], 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
            array(@number_format(((@$leadssum[$row->mailing_unique_id]+@$crossleadsSum[$row->mailing_unique_id])/$row->total_sent)*100, 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\"")
           );
但是当我显示DataTables中的所有数据时,排序是不正确的。表认为1.800小于999,但它是千分之一。数据如下所示:

999
888
5.656
4.655
322
2.333
122
编辑-----------------

这是主要查询:

$query = sprintf("
           SELECT stat_mailings.mailing_id, stat_mailings.cat_id, stat_mailings.mailing_name, stat_mailings.mailing_unique_id, stat_mailings.segment_id,
            stat_mailings.campaign_id, stat_mailings.landing_page, stat_mailings.total_sent, pecumail_segments.segment_name, categories.category FROM `stat_mailings`
            JOIN pecumail_segments ON stat_mailings.segment_id=pecumail_segments.segment_id
            JOIN categories ON stat_mailings.cat_id=categories.id      
这是我的代码,我正在打印所有数据:

 $table = new datatable("100%", "border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-left: auto;margin-right: auto;margin-left: -135px;\""); 

   $table->th("Mailing ID", "Unique id", "Mailing", "UTM campaign", "Segment", "Vezonden", "Views", "CTR", "Leads", "STL","Conversie", "Crossviews", "Crossleads","Crossconv","STLa");


   $analyzedata = getAnalyze();
   $leads = getLeads();
   $views = getViews();
   $crossviews = getCrossViews();
   $crossleads = getCrossLeads();



      while ($row1 = $leads->fetch_object()) {  
        $leadsData = count($row1->pema_mid);        
        @$leadssum[$row1->pema_mid] += $leadsData; 
      } 

      while ($row2 = $views->fetch_object()) {
        $countedViews = count($row2->pema_mid);        
        @$viewSum[$row2->pema_mid] += $countedViews;
      }

      while ($row3 = $crossviews->fetch_object()) {
        $countedCrossViews = count($row3->pema_mid);        
        @$crossviewSum[$row3->pema_mid] += $countedCrossViews;
      }

       while ($row4 = $crossleads->fetch_object()) {
        $countedCrossLeads = count($row4->pema_mid);        
        @$crossleadsSum[$row4->pema_mid] += $countedCrossLeads;
      }


      while($row = $analyzedata->fetch_object()){


          $totalSent = number_format($row->total_sent, 0, '.', '.');

       $table->td(              
                array($row->mailing_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array($row->mailing_unique_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array($row->mailing_name, "width=\"300\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array($row->campaign_id, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array($row->segment_name, "width=\"100\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""), 
                array($totalSent, "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(number_format(@$viewSum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(@number_format((@$viewSum[$row->mailing_unique_id] * 100)/$row->total_sent,  2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(number_format(@$leadssum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(@number_format((@$leadssum[$row->mailing_unique_id]*100)/$row->total_sent,2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(@number_format((@$leadssum[$row->mailing_unique_id] * 100)/@$viewSum[$row->mailing_unique_id], 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(number_format(@$crossviewSum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(number_format(@$crossleadsSum[$row->mailing_unique_id],0, '.', '.'), "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(@number_format((@$crossleadsSum[$row->mailing_unique_id] * 100)/@$crossviewSum[$row->mailing_unique_id], 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\""),
                array(@number_format(((@$leadssum[$row->mailing_unique_id]+@$crossleadsSum[$row->mailing_unique_id])/$row->total_sent)*100, 2, '.', '.').'%', "width=\"20\" style=\" border-bottom-width: 1px; border-bottom-style: solid;\"")
               );

 }


  echo  $html = $table->getHTML();
这是我的DataTable脚本

$(document).ready(function() {
$('#example').dataTable( {
    "aoColumns": [
        null,
        null,
        null,
        { "sType": "numeric-comma" },
        { "sType": "numeric-comma" },
        { "sType": "string" },
        { "sType": "formated-num" },
        { "sType": "percent" },
        { "sType": "numeric-comma" },
        { "sType": "percent" },
        { "sType": "percent" },
        { "sType": "numeric-comma" },
        { "sType": "percent" },
        { "sType": "percent" },
        null
    ]
} );

})

您必须从数据库中对此进行排序。查看您的代码

while ($row1 = $leads->fetch_object()) { } 
看起来它一次从表1中抓取一个对象或一行。如果它这样做了,你就无法在事后对它进行排序。您必须从数据库中对其进行排序,或者从具有fetch_object()函数的类中对其进行排序——这可能会循环遍历结果并将其创建为对象?如果该类恰好是迭代器实现,那么您只能选择从数据库中对其进行排序


在PHP中,唯一可以排序的方法是将值作为键并按键对数组进行排序,但显然,如果有两个或两个以上的值相同,它们将相互覆盖,则无法进行排序。

您必须将实际值存储在单独的字段中,以便对这些值进行排序。为什么要隐藏所有错误?这是一个糟糕的设计。5.656实际上是数据库中的值吗?还是你要把它转换成那样?换句话说,表中的值是什么?因为它说的是零除,如果存在零除,我需要0%。这就是为什么我要隐藏它。如果我不这样做,我就空了value@djjjuk我在数据库中的值是5656,但当我显示它们时,我将其格式化为5.656