drs3925 2013-08-22 08:44
浏览 23
已采纳

HTML表类的空数据数组

I'm attempting to do some research and not finding exactly what I'm looking for. I'm using Codeigniter and the HTML Table Class and trying to find out what I should do in my code in the event $inbox_messages is an empty array. Reason for this is because I put the together the table headings and cell data in the table inside the if statement. I"m not sure what to do for the else if its an empty array because in my view file I tell it to generate the table.

// Retrieve all user inbox messages that have not been deleted by the user..
$inbox_messages = array();

// Place to dump the inbox messages object variable to verify it is the expected properties and values for the inbox messages object.
// vardump($inbox_messages);

// Check to see if there are messages returned in the inbox messages object.
if (!empty($inbox_messages))
{
    // Add headings to the top of the table for the inbox messages html table.
    $this->table->set_heading(form_checkbox(), 'Date Sent', 'Subject', 'From');

    // Loop through the inbox messages object and display data for each row.
    foreach ($inbox_messages AS $message)
    {
        $this->table->add_row(form_checkbox(), date('F d, Y', strtotime($message->date_sent)), $message->subject, $message->first_name . ' ' . $message->last_name);
    }
}
else
{
    // Figure out what to do if object is empty                 
}
  • 写回答

1条回答 默认 最新

  • doutang1873 2013-08-22 09:02
    关注

    You can show no messages notification as said @Rajeev Ranjan like following codes:

    if (empty($inbox_messages)) {
    
        $empty_row = array('data' => 'You have no messages', 'colspan' => 4);
        $this->table->add_row($empty_row);
    
    } else {
        foreach ($inbox_messages AS $message)
        {
            $this->table->add_row(form_checkbox(), date('F d, Y', strtotime($message->date_sent)), $message->subject, $message->first_name . ' ' . $message->last_name);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算