【问题标题】:how change div class according to a php condition - CodeIgniter如何根据 php 条件更改 div 类 - CodeIgniter
【发布时间】:2014-05-11 14:40:51
【问题描述】:

我想改变这个表的 div 的颜色(数据库中所有 status = no 的记录),这意味着未读消息应该有不同的 div 类。我不知道该怎么做,我使用 codeigniter 作为我的框架

我的看法

<div class="row">
    <div class="span10 box" style="padding: 10px;">
        <?php  echo form_open('admin/messages'); ?><!-- start of the form -->
        <p>Recent Messages</p>
        <table class="table hovered">
            <thead>
            <tr class="selected">
                <th class="text-left">Name</th>
                <th class="text-left">Email</th>
                <th class="text-left">Phone</th>
                <th class="text-left">Message</th>
            </tr>
            </thead>
            <tbody>
            <?php

            if(isset($records)) :
            foreach($records as $row) :
                ?>
                <tr>
                    <td class="right"><?php  echo $row->contactus_name; ?></td>
                    <td class="right"><?php  echo $row->contactus_email; ?></td>
                    <td class="right"><?php  echo $row->contactus_phone; ?></td>
                    <td class="right tertiary-text-secondary text-justify"><?php  echo $row->contactus_comment; ?></td>
                </tr>
            <?php  endforeach; ?>
            </tbody>
            <tfoot></tfoot>
        </table>
        <?php else : ?>
            <p>No records</p>
        <?php  endif; ?>
    </div>
    <div class="span3">
        <nav class="sidebar dark">
            <ul>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Inbox <strong>
                            <?php if(isset($count)){echo '<div class="brand"><div class="badge bg-red">'.$count.'</div></div>';}?>


                            </strong>
                    </a>
                </li>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Send
                    </a>
                </li>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Newsletter/Ad
                    </a>
                </li>
            </ul>
        </nav>
    </div>
    <?php  echo form_close(); ?><!-- END of the form -->
</div>

【问题讨论】:

    标签: php jquery html css codeigniter


    【解决方案1】:

    提供指向/您的代码的链接将使我们能够提供更具体的建议,但总的来说:

    <?php if ($foo == 'bar') { $class_name = 'class1'; } else { $class_name = 'class2'; } ?>
    <div class="<?php echo $class_name; ?>">
    

    【讨论】:

      【解决方案2】:
      foreach($results as $row)
      {
           echo '<div '. ($row->read == 0 ? ' class="unread"': '') .'>Your content</div>';
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-13
        • 2014-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 1970-01-01
        相关资源
        最近更新 更多