I have searched for an answer to this problem all over the web and here at Stackoverflow. Nothing seems to help. This should be a very simple function. I have multiple records with the same content EXCEPT a field called level. I want to find the record with the highest int value in level. An example would be that I have multiple records with the same userid and email but the first record starts at level 1, the next may be level 2 and then the next may be level 1 again. I want to find the record with level = 2. My code is very simple.
$LoginRS__query=sprintf("SELECT userid, email, level FROM orders WHERE userid=%s AND email=%s ORDER BY level DESC LIMIT 1", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
For some this works correctly, returning the record with level = 2, 3, 8, 9, whatever. For others it will only return the record with level = 1. The field level is int length 1. I'm running php Version 5.3.28 and MySQL 5.5.36
Any ideas anyone? Like most, I'm in a rush. Thanks...
I didn't realize that level was a reserved word. I have been using the same table definitions and writing other scripts using level with no problems until now. I am checking for errors and it is not returning any. When checking the result with
foreach ($row_LoginRS as $key=>$val)
echo $key. ": ".$val. "
";
I normally get:
userid: 9999
email: email@email.com
level: 1 (or 2 or 3).
That looks correct.
I tried enclosing in ticks as suggested -
SELECT userid, email, level
... and/or/both ORDER BY 'level'
and it returns:
userid: 9999
email: email@email.com
level: level
My original query looks correct:
string(120) "
SELECT userid, email, level FROM orders WHERE userid='9999' AND email='email@email.com' ORDER BY level DESC LIMIT 1
"
and when using ticks I get:
string(120) "
SELECT userid, email, 'level' FROM orders WHERE userid='9999' AND email='email@email.com' ORDER BY 'level' DESC LIMIT 1
"
I'm not sure about the MySQL client question. phpinfo return:
Active Persistent Links 0
Active Links 0
Client API version 5.5.36
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib64 -lmysqlclient