返回NULL不能使用制表符插件

时间:2012-03-10 19:38:24

标签: php jquery codeigniter datatables

当我为messages对象返回数据行时,此代码有效,但是如果没有,则返回NULL,在这种情况下,我很难让此代码仍然正确显示,以便它可以与标签插件我起来了。我正在为我的桌子使用数据表。

有人有什么想法吗?

<!-- Start of the main content -->
<div id="main_content">

<h2 class="grid_12">Personal Messages</h2>
<div class="clean"></div>

<div class="grid_8">

    <div id="tab-panel-1" class="box">

        <div class="header">
            <img src="<?php echo base_url() ?>assets/img/icons/packs/fugue/16x16/shadeless/mail.png" width="16" height="16" />
            <h3>Messages</h3><span></span>
            <ul>
                <li><a href="#tab-1">Inbox Messages</a></li>
                <li><a href="#tab-2">Sent Messages</a></li>
                <li><a href="#tab-3">Compose Message</a></li>
            </ul>
        </div>
        <div class="content">
            <div id="tab-1" class="tab-content">
                <table id="inbox" class="table dataTable">
                    <thead>
                        <tr>
                            <th></th>
                            <th>Date</th>
                            <th>Subject</th>
                            <th>From</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        if ($messages[0] !== NULL)
                        {
                            foreach ($messages[0] AS $message)
                            {
                                echo '<tr>';
                                    echo '<td style="text-align: center">';
                                    if ($message->message_read == 1)
                                    {
                                        echo '<img src='.base_url().'assets/img/icons/packs/fugue/16x16/mail-open.png />';
                                    }
                                    else
                                    {
                                        echo '<img src='.base_url().'assets/img/icons/packs/fugue/16x16/mail.png />';
                                    }
                                    echo '</td>';
                                    echo '<td>'.date('F d, Y', strtotime($message->date_sent)).'</td>';
                                    echo '<td>'.$message->subject.'</td>';
                                    echo '<td>'.$message->first_name.' '.$message->last_name.'</td>';
                                    echo '<td></td>';
                                echo '</tr>';
                            }
                        }
                        else
                        {
                            echo '<tr>';
                            echo 'No records';
                            echo '</tr>';
                        }
                        ?> 
                    </tbody>
                </table>
            </div>

            <div id="tab-2" class="tab-content">
                <table id="sent" class="table dataTable">
                    <thead>
                        <tr>
                            <th></th>
                            <th>Date</th>
                            <th>Subject</th>
                            <th>To</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        if ($messages[1] !== NULL)
                        {
                            foreach ($messages[1] AS $message)
                            {
                                echo '<tr>';
                                    echo '<td style="text-align: center">';
                                    if ($message->message_read == 1)
                                    {
                                        echo '<img src='.base_url().'assets/img/icons/packs/fugue/16x16/mail-open.png />';
                                    }
                                    else
                                    {
                                        echo '<img src='.base_url().'assets/img/icons/packs/fugue/16x16/mail.png />';
                                    }
                                    echo '</td>';
                                    echo '<td>'.date('F d, Y', strtotime($message->date_sent)).'</td>';
                                    echo '<td>'.$message->subject.'</td>';
                                    echo '<td>'.$message->first_name.' '.$message->last_name.'</td>';
                                    echo '<td></td>';
                                echo '</tr>';
                            }
                        }
                        else
                        {
                            echo '<tr>';
                            echo 'No records';
                            echo '</tr>';
                        }
                        ?> 
                    </tbody>
                </table>
            </div>

            <div id="tab-3" class="tab-content">
                <?php echo form_open('') ?>
                        <div class="_100">
                            <p>
                                <?php echo form_label('Recipient', 'recipient'); ?>
                                <select name="to" class="required">
                                    <option></option>
                                    <?php
                                    foreach ($users AS $user)
                                    {
                                        echo '<option>'.$user->first_name.' '.$user->last_name.'</option>';
                                    }
                                    ?>
                                </select>
                            </p>
                        </div>
                        <div class="_100">
                            <?php echo form_label('Subject', 'subject'); ?>
                            <?php echo form_input('subject', '', 'class=required'); ?>
                        </div>
                         <div class="_100">
                            <?php echo form_label('Message', 'message'); ?>
                            <?php echo form_textarea('message', '', 'class=required'); ?>
                        </div>
                        <?php echo form_hidden('sender', $this->session->userdata('user_id')); ?>   
                    <div class="actions">
                        <div class="actions-left">
                            <?php echo form_reset('reset', 'Reset'); ?>           
                        </div>
                        <div class="actions-right">
                            <?php echo form_submit(array('id' => 'submit', 'name' => 'submit'), 'Submit Message'); ?>           
                        </div>
                    </div>
                <?php echo form_close(); ?>
            </div>

        </div> <!-- End of .content -->

        <div class="clear"></div>

    </div>

</div>

<div class="clear"></div>

这是它的作用: http://jsfiddle.net/MGram/

1 个答案:

答案 0 :(得分:1)

echo '<tr>';
echo 'No records';
echo '</tr>';

需要td

echo '<tr><td colspan="5">';
echo 'No records';
echo '</td></tr>';

javascript和tabs插件的实例化似乎存在问题。我没有在任何地方看到标签的js。但我确实看到选择中页面上存在CI错误:

<select name="to" class="required">
                                        <option></option>

                                        <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Invalid argument supplied for foreach()</p>
<p>Filename: views/pmsystem.php</p>
<p>Line Number: 121</p>

</div>                                    </select>

有时会搞乱javascript的东西。

你在错误控制台中得到了什么吗?

我们可以看到js吗?