getting the max int from a mysql column
#1

pawn Код:
GetTempBanSlot()
{
    mysql_query("SELECT MAX(Banid) FROM Bans");
    mysql_store_result();
    new slot = mysql_fetch_int();
    mysql_free_result();
    if(slot <= 0) slot = 0;
    return slot+1;
}
it always returns 1.
Reply
#2

pawn Код:
if(slot <= 0) return slot = 0;
Slot being 0 before +1 = 1.
Reply
#3

what are u talking about? i put that there if its -0 but theres 1 in table.. should it should return 2?
Reply
#4

All uppercase/lowercase is correct?
Reply
#5

Your confusing me... You have:
pawn Код:
if(slot <= 0) slot = 0;
    return slot+1;
Meaning equals 0 or less than 0 then set to one.

So I suggest that:
pawn Код:
mysql_query("SELECT MAX(Banid) FROM Bans");
That is already 0 or less.

and return slot+1 will set to 1. Setting something to 0 and adding 1 trying to get higher than 1 will not work.
Reply
#6

1 is the default auto incrementing number, do you have any more rows?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)