Welcome Guest, Not a member yet? Register   Sign In
php-activerecord statement
#1

[eluser]Carmichael[/eluser]
I'd like to find out if a receiver has a unread message from a sender. By doing this I've to check the last sent message from sender to receiver if it's read or not. If it's not read read_at is empty.

I don't now how to write the sql statement for that in php-activerecord.

The messages table
Code:
id | sender_id | receiver_id | subject | message | sent | read_at

I tried this but it's not giving me the result I want because this will return FALSE as long as sender has sent messages before to receiver. I just want it to check the last message sent to receiver from sender and return a boolean.
Code:
function sender_can_send_to_receiver($receiver)
    {
        $message = Message::find_by_sender_id_and_receiver_id($this->user_id, $receiver);
        
        if (empty($message->read_at))
            return FALSE;
        else
            return TRUE;
    }
#2

[eluser]Carmichael[/eluser]
I solved it.
Changed the standard value for read_at to null and...

Code:
function sender_can_send_to_receiver($receiver)
    {
        $message = Message::find_by_sender_id_and_receiver_id_and_read_at($this->user_id, $receiver, 'NOT NULL');
        
        if ($message)
            return TRUE;
        else
            return FALSE;
    }
#3

[eluser]Carmichael[/eluser]
Actually I did not. Help me! Tongue
#4

[eluser]Cristian Gilè[/eluser]
Code:
$this->db->where('read_at IS NULL', NULL, false);
$query = $this->db->get('messages');
#5

[eluser]Carmichael[/eluser]
It works fine now. I removed the single quotes marks from NULL.




Theme © iAndrew 2016 - Forum software by © MyBB