开发者

Select not more than

I was wondering if anyone could help me with this minor problem.

I want to select something from the database, where the number is not more than a set number.

This is what i have (snippet):

$Level = "1"; //Retrieved from the DB, just keeping it simple.
@$Query = mysql_query("SELECT * FROM users,store WHERE users.ID = '$ID' AND store.LevelReq <='users.Level'");

The problem with this, it doesn't display anything that equals $level.

(Item ... Level: 0) 开发者_运维问答- Displays (Item ... Level: 1) - Doesn't display.

So what i'd like is the equivalent of php's !>1 (not more than 1) but in MYSQL format if possible, however this doesn't work.


You should remember that 'not more than' is always the same as 'lower than and equal to', so you should use field <= value. (So in your case: field <= 1.)


I assume that Level is a field of the table users, if it is true, then you have a quote problem in you query, and query with the PHP var, try:

$Query = @mysql_query("SELECT * FROM users,store WHERE users.ID = '{$ID}' AND store.LevelReq <= {$Level}");


tables and columns are escaped separately, therefor, instead of 'users.Level', try user.'level'. (table.column)

$Level = "1"; //Retrieved from the DB, just keeping it simple.
@$Query = mysql_query("SELECT * FROM users,store WHERE users.ID = '$ID' AND store.LevelReq <= users.'Level'");


You are comparing store.LevelReq to the string "users.Level", not the column users.Level. Remove the quotes around users.Level, and everything should be well!


Are you sure you shouldn't use backticks instead of single quotes? Like this:

$Level = "1"; //Retrieved from the DB, just keeping it simple.
@$Query = mysql_query("SELECT * FROM users,store WHERE users.ID = '$ID' AND store.LevelReq <=`users`.`Level`");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜