Guest
Public paste!

Flippz

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 0.97 KB | Hits: 11 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3. $userId=$_REQUEST["userId"];
  4.  
  5. include('config.inc.php');
  6. include('database.inc.php');
  7. $randomUserId=0;
  8.  
  9. $result      =mysql_query("SELECT * FROM chats WHERE userId = $userId ");
  10.  
  11. while ($row=mysql_fetch_array($result))
  12.     {
  13.     $randomUserId=$row["randomUserId"];
  14.     }
  15.  
  16. if ($randomUserId == 0)
  17.     {
  18.     $result=mysql_query("SELECT * FROM users WHERE id <> $userId AND inchat like 'N' ORDER BY RAND() LIMIT 1");
  19.  
  20.     while ($row=mysql_fetch_array($result))
  21.         {
  22.         $randomUserId=$row["id"];
  23.         }
  24.  
  25.     if ($randomUserId != 0)
  26.         {
  27.         mysql_query("INSERT INTO chats (userId,randomUserId) values($userId, $randomUserId) ");
  28.         mysql_query("INSERT INTO chats (userId,randomUserId) values($randomUserId, $userId) ");
  29.  
  30.         mysql_query("UPDATE users SET inchat='Y' WHERE id = $userId ");
  31.         mysql_query("UPDATE users SET inchat='Y' WHERE id = $randomUserId ");
  32.         }
  33.     }
  34.  
  35. echo $randomUserId;
  36. mysql_close($con);
  37. ?>