Random user connection only in PHP solution

So, I want to pair users only in PHP:

First get one available user id // not random right now

mysql_query('SELECT id FROM users WHERE state="0" LIMIT 1'); //state 0 = user avaliable, 1 = talking/playing with someone

$ available_id = stuffs to get id from request

And then update:

$result = mysql_query('UPDATE INTO users SET state="1" WHERE (id=$available_id OR id=$my_id) AND state="0"');

if $result == false, then this means that no row has been updated. So, back to the first step,
if $result == trueso what? this may mean that my line is updated or available to the user, or both. I am confused how to handle this.

+3
source share
5 answers

Try this code

$first=mysql_query('select id from users where state =0 limit 1');

$available=mysql_fetch_row($first);
$available_id=$available['id'];

$result = mysql_query('UPDATE INTO users SET state="1" WHERE
(id=$available_id OR id=$my_id) AND state="0"');
0
source

mysql_queryreturns falsefor error. You can check the number of rows updated using mysql_affected_rows

+4

mysql_num_rows(); http://php.net/manual/en/function.mysql-num-rows.php mysql_affected_rows(); http://php.net/manual/en/function.mysql-affected-rows.php

$result = mysql_query('UPDATE INTO users SET state="1" WHERE (id=$available_id OR id=$my_id) AND state="0"'); remove into

+1

,

INSERT, UPDATE, DELETE, DROP, etc., mysql_query () returns TRUE success or FALSE on error.

if mysql_query return FALSE means the query is get failed and has a syntax error, if TRUE, it means the query is successful, but it does not mean that the row has been updated.

You can really check if the row is updated or not with mysql_affected_rows after successfully executing the UPDATE query

0
source
$id = mysql_query('SELECT id FROM users WHERE state="0" LIMIT 1');
$uid = mysql_fetch_array($id);

$id2 = mysql_query('SELECT id FROM users WHERE status="0" AND `id`!='".$uid."' ORDER BY rand LIMIT 1');
$uid2 = mysql_fetch_array($id2);

mysql_query("UPDATE user SET `user`='1' WHERE `id` IN($uid,$uid2)");

and connect it in the table of pairs.

0
source

All Articles