简体   繁体   中英

Codeigniter - Don't show card when data is empty

An image of the two pie charts and empty cards

I don't want to show the empty card because it doesn't have data. I have already checked my SQL query but there seems to be no problem. I think the problem comes from the if(...). Could you help me to solve this problem? Here is my code:

In my View:

<?php
    if(empty($js11))
    {
        echo '';

    } else {
        $ht='';
        $ht.='<div class="col-12 col-sm-12 col-md-12 col-lg-12">';
        $ht.='<div class="ibox float-e-margins">';
        $ht.='<div class="ibox-title">';
        $ht.='<h5>by Quantity</h5>';
        $ht.='</div>';
        $ht.='<div class="ibox-content" style="padding-right: 8px;padding-left: 8px;">';
        $ht.='<div>';
        $ht.='<div id="apartment" height="700" width="700" style="position: fixed;"></div>';
        $ht.='</div>';
        $ht.='</div>';
        $ht.='</div>';
        $ht.='</div>';
        echo $ht;
    }
?>

<?php

    if(empty($js9))
    {
        echo '';
    } else {
        $hts='';
        $hts.='<div class="col-12 col-sm-12 col-md-12 col-lg-12">';
        $hts.='<div class="ibox float-e-margins">';
        $hts.='<div class="ibox-title">';
        $hts.='<h5>Landed by Quantity</h5>';
        $hts.='</div>';
        $hts.='<div class="ibox-content" style="padding-right: 8px;padding-left: 8px;">';
        $hts.='<div>';
        $hts.='<div id="landed" height="700" width="700" style="position: fixed;"></div>';
        $hts.='</div>';
        $hts.='</div>';
        $hts.='</div>';
        $hts.='</div>';
        echo $hts;
    }
?>

Solved, I just add if(.empty($data)){...} on my controller if I just want to show the card that has any data.

here is the code:

$jscript11 = '';
if(!empty($dt9)){
    $bgColor = '"#2fb4ed","#ba68c8","#33e0ff","#0fe07f","#ffb74d","#4caf50","#ff7043"';
    $jdata11= '';
    $jdata12='';
    $jcolor= '';
    // $jjum11= '';

    foreach ($apt as $key => $row) {
        $qty = ($row->sales_qty / $row->total_sales_qty) * 100;
        $qty = number_format($qty, 2);
        $qty_unit = $row->sales_qty;

        $qtyamt = ($row->sales_amt / $row->total_sales_amt) * 100; 
        $qtyamt = number_format($qtyamt, 2);
        $qtyAmt = $row->sales_amt;

        $p11 = '["'.$row->payment_descs.'",'.$qty_unit.']';
        $p12 = '["'.$row->payment_descs.'",'.$qtyAmt.']';
        $c1 = $bgColor;
        $jdata11.= $p11.',';
        $jcolor.= $c1.',';
        $jdata12.= $p12.',';
    }

    $jdata11=substr($jdata11,0,-1);
    $jcolor=substr($jcolor,0,-1);
    $jdata12=substr($jdata12,0,-1);

    $jscript11.='var chart1 = c3.generate({bindto: "#paymentaptqty",padding: 
                     {bottom: 20,top:10}, data: {';
    $jscript11.='         columns: [ '.$jdata11.'], ';
    $jscript11.='         type : "pie",        ';
    $jscript11.='         colors :['.$jcolor.']         ';
    $jscript11.='     }, ';
    // $jscript11.='     size: { ';
    // $jscript11.='          width: 300, ';   
    // $jscript11.='          height: 300, '; 
    // $jscript11.='     }, '; 
    $jscript11.='     legend: { ';
    $jscript11.='          show: false, '; 
    $jscript11.='          responsive: true, ';
    $jscript11.='     }, '; 
    $jscript11.='     tooltip: { ';
    $jscript11.='         format: { ';
    // $jscript11.='             // title: function (d) { return 'Data ' + d; }, ';
    $jscript11.='             value: function (value, ratio, id) { ';
    $jscript11.='                 return formatNumber(value); ';
    $jscript11.='             } ';
    $jscript11.='         } ';
    $jscript11.='     } ';
    $jscript11.=' });';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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