R
R
rusgayfer2018-06-10 16:26:16
MySQL
rusgayfer, 2018-06-10 16:26:16

How to make the right query?

Here is the code:

while($cal = $sqlotv->fetch_array()) {
if($cal['user_id'] == $user_id) {
exit();
} else {
if(mb_strtolower($body) == '!старт' || mb_strtolower($body) == '!поиск') {
  
$sqlotvin = $mysqli->query(" INSERT INTO `anon_chat` (`id_group`, `user_id`, `sex`, `user_id2`) VALUES ('".$group_id."', '".$user_id."', '".$sex."', '".$cal['user_id']."') ");	
$sqlotvup = $mysqli->query(" UPDATE `anon_chat` SET `user_id2` = '".$user_id."' WHERE `stop` = '0' LIMIT 1"); // Добавляем id к свободному пользователю
$sqlotvups = $mysqli->query(" UPDATE `anon_chat` SET `user_id2` = '".$cal['user_id'] ."' WHERE `user_id` = '".$user_id."' AND `stop` = '0' LIMIT 1");

$message = urlencode('Собеседник найден! Подключаю...');
$url = json_decode(file_get_contents("https://api.vk.com/method/messages.send?message={$message}&user_ids={$user_id},{$cal['user_id']}&access_token={$token_message}&v={$v}"));
 
 }
    }
}

I need to add $user_idto a free user_id2user in the field who has stop = 0, and then add the same user to another user_id2
If it’s not clear, I’ll show a screen like this, it should turn out
5b1d26a5a187c907862871.png
Find a user who is free, whose user_id2 and stop are 0 and add them to each other in the user_id2 fields id, that is, two users exchange their id
. It works for me, but brings it to different ones, confusion occurs, since I did it wrong

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question