I can't get the following to work as expected, tried what I have seen in other examples and solutions but still can't this right.
Dim pos As String = Nothing
Try
OpenUserDB()
Dim cmd43 As MySqlCommand = New MySqlCommand("SELECT COUNT(id) AS position FROM users " & _
"WHERE user_id <= @UserID ORDER BY food_total DESC", connUser)
cmd43.Parameters.AddWithValue("@UserID", UserID)
Dim reader As MySqlDataReader = cmd43.ExecuteReader
If reader.Read() Then
pos = reader("position").ToString() & positionName(reader("position").ToString())
End If
Return pos
Catch ex As Exception
Dim err As New ErrorLog
err.logError(Format(Date.Now, "dd-MM-yyy hh:mm:ss ") & ex.ToString)
Return Nothing
Finally
CloseUserDB()
End Try
table users
| id | userID | food_total |
| 1 | g01 | 84 |
| 2 | g02 | 83 |
| 3 | g03 | 34 |
I queried with UserID = g02
with expected result being 2, but got 3.
The user is suppose to be the 2nd User but it returns the wrong position. Help will be appreciated.