Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Randomly pairing users only in PHP - solution

Tags:

php

mysql

So i wanna pairing users only in PHP:

First, get one avaliable user id //right now not random

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 query

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 it mean that no one row has updated. So back to First step,
if $result == true then what? it can mean that my row has updated or available user, or both. I am confused how to done with it.

like image 633
ElSajko Avatar asked Jun 30 '26 22:06

ElSajko


1 Answers

mysql_query returns false for error. You can check the count of updated rows using mysql_affected_rows

like image 86
Alex Pliutau Avatar answered Jul 03 '26 15:07

Alex Pliutau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!