Answer the question
In order to leave comments, you need to log in
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);
}
}
Answer the question
In order to leave comments, you need to log in
Check incoming parameters
Look in debug mode query to the database
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question