I have table:
user_id | song_id| points
--------|----------------
2 | 1 | 0
2 | 2 | 1
2 | 3 | 2
2 | 4 | 3
2 | 5 | 4
And I need to check if the user have changed the points value.
Therefore it should be something like:
while ($row = mysql_fetch_array($query)) {
$userID = $row['user_id'];
$songID = $row['song_id'];
$points = $row['points'];
if($songID-$points==1){
echo $userID."<br>";
}
But this will print out every occasion of userID where the song-id – points=1.
I need to print out only these user_id’s that have all the values =1 and the username must echo’d only once.
EDIT:
SELECT DISTINCT user_id WHERE (song_id - points) = 1
This is half way there. This echo’s user_ids’ where the song_id – points = 1, but if the user is reordered (i use jQuery sortable) the list, then there can be some rows that is “song_id – points = 1”.
My script must echo only these user_id-s, where users every song_id – points = 1, not only one
You can first filter the users which has modified point values:
Then you can use fetch the users which doesn’t fit the above condition:
According to your last edit this last SQL statement might work.
You can check a working example.