Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 2.02 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Checking users options from default
  2. user_id | song_id| points
  3. --------|----------------
  4.   2     |  1     |  0
  5.   2     |  2     |  1
  6.   2     |  3     |  2
  7.   2     |  4     |  3
  8.   2     |  5     |  4
  9.        
  10. while ($row = mysql_fetch_array($query)) {
  11.     $userID = $row['user_id'];
  12.     $songID = $row['song_id'];
  13.     $points = $row['points'];
  14. if($songID-$points==1){
  15.  echo $userID."<br>";
  16.  
  17. }
  18.        
  19. SELECT DISTINCT user_id WHERE (song_id - points) = 1
  20.        
  21. SELECT DISTINCT user_id FROM table
  22. WHERE (song_id - points) != 1
  23.        
  24. SELECT DISTINCT user_id FROM table
  25. WHERE user_id NOT IN (
  26.   SELECT DISTINCT user_id FROM table
  27.   WHERE (song_id - points) != 1
  28. )
  29.        
  30. SELECT DISTINCT user_id FROM table WHERE (song_id - points) = 1
  31.        
  32. SELECT table.user_id
  33. FROM table
  34. LEFT JOIN (
  35.     SELECT user_id, COUNT(*) AS C FROM table) AS T2
  36. ON table.user_id = T2.user_id
  37. WHERE (table.song_id - table.points) = 1
  38. GROUP BY table.user_id
  39. HAVING COUNT(*) = T2.C
  40.        
  41. select user_id from (
  42.   select user_id, if(song_id - points = 1, 0, 1) flag from t
  43. ) as S
  44. group by user_id
  45. having sum(flag) = 0
  46.        
  47. select distinct t1.user_id from t t1
  48. where not exists (
  49.   select * from t t2
  50.   where t2.song_id - t2.points != 1 and t1.user_id = t2.user_id
  51. )
  52.        
  53. $old_id = '';
  54. $good   = false;
  55. while($row = mysql_fetch_array($query)){
  56.     //check to see if we have a new user ...
  57.     if($row['user_id'] != $old_id){
  58.         //check to see if all values were == 1
  59.         if($good){
  60.             echo $old_id . '<br />';
  61.         }
  62.         //re-initialize variables
  63.         $good   = true;
  64.         $old_id = $row['user_id'];
  65.     }
  66.     //if value != 1, we won't print the user ...
  67.     if($row['song_id'] - $row['points'] != 1){
  68.         $good = false;
  69.     }
  70. }
  71. //final end-of-loop condition ...
  72. if($good){
  73.     echo $old_id . '<br />';
  74. }
  75.        
  76. SELECT user_id, sum(song_id) as song_total, sum(points) as point_total, count(*) AS cnt FROM table GROUP BY user_id
  77.        
  78. while($row = mysql_fetch_array($query)){
  79.     if($row['cnt'] == ($row['song_total'] - $row['point_total'])){
  80.         echo $row['user_id'] . '<br />';
  81.     }
  82. }