• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Loop issues.

Nothxbye

Banned User
Joined
Jan 22, 2012
Messages
1,124
Reaction score
173
Hello,

I've got loop:
Code:
for i = 1, 4 do 
  print(i)
  db.query("UPDATE `player_items` SET `serialId` = "..i.." WHERE `serialId` = 0")
end

"Print" returns:
1
2
3
4

But the "db.query" in database returns
1
1
1
1

Why it happens?
 
Do you mean you tried to print(db.query("..."))?
because if a query succeeds then it returns 1 (true) if it fails it returns 0 (false)
 
Do you mean you tried to print(db.query("..."))?
because if a query succeeds then it returns 1 (true) if it fails it returns 0 (false)

I'm not talking about true of false i know it returns true if i print(db.query("..."))

Bassicaly i need result like this one:
nowy-obraz-mapy-bitowej.jpg

But the result is 1,1,1,1
nowy-obraz-mapy-bitowej-2-.jpg

Most likely because your 'serialId' column is a boolean and needs to be changed to an integer.

I think it's int not bolean column:
Look
nowy-obraz-mapy-bitowej-3-.jpg
 
Set it to an int(11).
Still same. Also i noticed something strange. Even if i exute this loop once it setting value 1 to more than 4 queries as is in loop:

Code:
function onSay(cid, words, param)
   for i = 1, 4 do 
     print(i)
      db.query("UPDATE `player_items` SET `serialId` = "..i.." WHERE `serialId` = 0")
   end
end
print shows: 1,2,3,4 in console but in database i have 1,1,1,1,1,1....

nowy-obraz-mapy-bitowej.jpg

What i doing wrong?
 
This was my problem "LIMIT 1;" at query ending
Code:
   for i = 1, 4 do
     print(i)
      db.query("UPDATE `player_items` SET `serialId` = "..i.." WHERE `serialId` = 0 LIMIT 1;")
   end

Problem solved.
 
Last edited:
Back
Top