如何根据php条件更改div类 - CodeIgniter

时间:2014-05-11 14:40:51

标签: php jquery html css codeigniter

我想更改此表的div的颜色(数据库中status = no的所有记录),这意味着未读消息应该具有不同的div类。我不知道如何做到这一点我使用codeigniter作为我的框架

enter image description here

我的观点

<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>

2 个答案:

答案 0 :(得分:2)

提供/您的代码的链接将允许我们提供更具体的建议,但总的来说:

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

答案 1 :(得分:0)

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