亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為 codeigniter 中的特定列數據賦予顏色?

如何為 codeigniter 中的特定列數據賦予顏色?

PHP
蠱毒傳說 2022-12-11 09:41:14
<?    foreach($customer as $customer_details)    {?>        <tr id="customer_details_<?=$customer_details['id']?>">            <?                 foreach($dyncust_fields as $dyncust_field)                {                    if($dyncust_field['add_to_listing']=='1')                    {                        echo "<td style='color:green;'>".$customer_details[$dyncust_field['attribute_name']]."</td>";                    }                }            ?>        </tr>    <? }?>這里我寫了一些代碼來顯示動態列的數據,這里我想給特定列的特定數據一個顏色。但它不工作。這里這一行$customer_details[$dyncust_field['attribute_name']]是用來根據動態列獲取表記錄的。在這里,$customer_details[$dyncust_field['attribute_name']] == 'cname'我希望單元格為紅色,否則顯示綠色。這個怎么做 ?。誰能幫幫我...
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

<?php

    foreach($customer as $customer_details)

    {?>

        <tr id="customer_details_<?=$customer_details['id']?>">

            <? 

                foreach($dyncust_fields as $dyncust_field)

                {

                    if($dyncust_field['add_to_listing']=='1')

                    {

                       $color = $customer_details[$dyncust_field['attribute_name']] == 'cname' ?'red':'green';

                       $search = array("{{color}}","{{data}}");

                       $replace = array($color,$customer_details[$dyncust_field['attribute_name']] );

                       $template =  "<td style='color:{{color}};'>{{data}}</td>";

                       echo str_replace($search,$replace,$template);

                    }

                }

            ?>

        </tr>

    <? }

?>

這$template是表格單元格的模板。$search數組中的值替換為$replace數組的值。這樣,你只需要自定義模板,搜索和替換數組。例如,以下是您在評論部分提出的問題的答案。


$template = "<td> <a href='#list-corp-client' class='view-asset-inbox-model m-r-5 text-info' data-from='corporate' data-id='{{id}}' data-pk='1' data-toggle='modal'>{{title}}</a> </td>";

$search = array("{{id}}","{{title}}");

$replace = array($customer_details['id'], $asset_details['title']);

echo str_replace($search,$replace,$template);


查看完整回答
反對 回復 2022-12-11
?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

<?php

    foreach($customer as $customer_details)

    {?>

        <tr id="customer_details_<?=$customer_details['id']?>">

            <? 

                foreach($dyncust_fields as $dyncust_field)

                {

                    if($dyncust_field['add_to_listing']=='1')

                    {

                        echo "<td style='".$customer_details[$dyncust_field['attribute_name']] == 'cname' ?'color:red':'color:green'."'>".$customer_details[$dyncust_field['attribute_name']]."</td>";

                    }

                }

            ?>

        </tr>

    <? }

?>

或者您可以將類定義為內聯樣式或外部樣式


<style>

  .text-red{

    color:red;

  }

  .text-green{

    color:green;

  }

</style>


<?php

    foreach($customer as $customer_details)

    {?>

        <tr id="customer_details_<?=$customer_details['id']?>">

            <? 

                foreach($dyncust_fields as $dyncust_field)

                {

                    if($dyncust_field['add_to_listing']=='1')

                    {

                       $styleClass = $customer_details[$dyncust_field['attribute_name']] == 'cname' ?'text-red':'text-green'

                       echo "<td class='$styleClass'>".$customer_details[$dyncust_field['attribute_name']]."</td>";

                    }

                }

            ?>

        </tr>

    <? }

?>


查看完整回答
反對 回復 2022-12-11
  • 2 回答
  • 0 關注
  • 104 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號