Reputation: 415
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
}
Upvotes: 0
Views: 136
Reputation: 10717
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);
}
}
Upvotes: 1