How can i get my delete messages function just appear for the user's own messages left on their friends page?
- by Hannah_B
I had been working on this trying the delete message button to work on my own profile page of my site. When I delete a message left by a friend it not only deletes it from the screen but deletes it from the database. The messages in the database have 4 fields: message_id, from, to and message. Here is my profile view that shows how Im deleting messages from my friends:
if(!empty($messages)){
foreach($messages as $message):
$delete = $message['message_id'];
//var_dump($message); ?>
<li><?=$message['from']?> says...: "<?=$message['message']?>"(<?=anchor("home/deleteMsg/$delete", 'delete')?>)</li> //this is where the delete button appears beside messages left
<?php endforeach?>
<?php }else{ ?>
<?php echo 'No messages left yet !!!'; }?>
Here is my controller showing the deleteMsg function called:
function deleteMsg($messageid) {
$this->messages->deleteMsg($messageid);
redirect('home');
}
Here is the messages model showing the deleteMsg model itself:
function deleteMsg($message_id)
{
$this->db->where(array('message_id' => $message_id));
$this->db->delete('messages');
}
Here is my friendprofile view where I want to implement the delete message command just so the button appears for messages Ive left and I can delete them. The delete button will not appear beside other friends comments on this page:
<li><?=$message['from']?> says...: "<?=$message['message']?>"</li>
Now I've tried creating a new delete Message function to no success so far, am I better off doing this than calling the same function? As this didnt work either.