I have a notifications section on my site and I am getting data from my table. There can be child notifications assigned to their parent, so I have parent_id in the table as shown below:
Below is the array I am getting
Array
(
[0] => stdClass Object
(
[user_title] => Mr
[user_firstname] => Richard
[user_lastname] => Knight-Gregson
[assignee_title] => Mr
[assignee_firstname] => Richard
[assignee_lastname] => Knight-Gregson
[created] => 2015-03-26 11:40:20
[id] => 61
[user_id] => 88
[description] => message for user rkg uid 88
[assignee] => 88
[parent_id] =>
[cc] =>
[bcc] =>
[status] => 0
)
[1] => stdClass Object
(
[user_title] => Mr
[user_firstname] => Richard
[user_lastname] => Knight-Gregson
[assignee_title] => Mr
[assignee_firstname] => Richard
[assignee_lastname] => Knight-Gregson
[created] => 2015-03-26 12:45:47
[id] => 71
[user_id] => 88
[description] => This is child
[assignee] => 88
[parent_id] => 61
[cc] =>
[bcc] =>
[status] => 0
)
[2] => stdClass Object
(
[user_title] => Mr
[user_firstname] => Ted
[user_lastname] => Chiles
[assignee_title] => Mr
[assignee_firstname] => Richard
[assignee_lastname] => Knight-Gregson
[created] => 2015-03-27 10:11:56
[id] => 207
[user_id] => 47
[description] => cc 88
[assignee] => 88
[parent_id] =>
[cc] => 88
[bcc] => 112
[status] => 0
)
[3] => stdClass Object
(
[user_title] => Mr
[user_firstname] => Richard
[user_lastname] => Knight-Gregson
[assignee_title] => Mr
[assignee_firstname] => Richard
[assignee_lastname] => Knight-Gregson
[created] => 2015-03-27 10:17:31
[id] => 209
[user_id] => 88
[description] => sadfasdfasd
[assignee] => 88
[parent_id] =>
[cc] => 88
[bcc] => 0
[status] => 0
)
)
Here is the code I have at the moment to loop through the array, what I need to add to this is to get all elements that have a parent_id and then display them under their repsective parent in a list...
<table class="notifications-table" border="1">
<tr>
<th>S No.</th><th>Date</th><th>Employee</th><th id="details">Details</th><th>Assignee</th><th>Action</th>
</tr>
<?php foreach($notifications as $row){ ?>
<?php foreach($row as $k){
} ?>
<tr <?php if($row->status){ echo "class='resolved'"; } ?> id="row-<?=$row->id;?>">
<td><?=$row->user_id?></td><td><?=date('d M, H:i',strtotime($row->created));?></td>
<td><?=$row->user_title.' '.$row->user_firstname.' '.$row->user_lastname;?></td>
<td>
row id is : <?=$row->id.' == '.$row->parent_id; ?>
<?php //echo $row->id.' == '.$row->parent_id; ?>
<?=$row->description; ?><span data-parent-id="<?=$row->id;?>" data-user-id="<?=$row->user_id;?>" id="add_not" data-featherlight="#send_child_message" data-id="add_child_notification" class="glyphicon glyphicon-plus"></span>
</td>
<td><?=$row->assignee_title.' '.$row->assignee_firstname.' '.$row->assignee_lastname;?></td>
<td><input <?php if($row->status){ echo "disabled"; } ?> value="<?=$row->id;?>" data-action="not" type="checkbox" /></td>
</tr>
<?php } ?>
</table>
I have tried a few things but just cant get what I want! Regards!