D
D
Dmitry Petrik2015-03-30 07:22:03
MySQL
Dmitry Petrik, 2015-03-30 07:22:03

Yii2 how to make a selection from a database?

I'm writing a chat. Through ajax I check whether a new message has arrived from the interlocutor. To do this, I call the function for receiving new messages and pass it the id of the last message that is visible in my chat window and the number of the chat room.

public function getNew($lastId, $chatRoom){
        $list = self::find()->where('id > :lastId and chat_room_id = :chat_room_id',[':lastId'=>$lastId, ':chat_room_id'=>$chatRoom])->orderBy('id')->asArray()->all();
        if(isset($list[0])){
            echo Json::encode($list);
        }
    }

In the request, I want to remove all messages whose id is greater than the id of the last message in my chat window.
However, I do not receive any records, apparently, the request is not correctly composed. What am I doing wrong?

Upd. Sam kosyachnik, the question is removed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2015-03-30
@opium

Check incoming parameters
Look in debug mode query to the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question