hipolitalakaj Posted January 14, 2019 Share Posted January 14, 2019 Hi! How can I get if the row value 1 then do something? local result = dbQuery("SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")) if(#result == 1) then dbExec(mysql, "UPDATE vehicle SET paintjob = ? WHERE id = ?", paintjob, vehicle:getData("veh:id")) else outputChatBox ( "Előbb szedd le a matricát!" ) end I get that warning in debugscript (so I think the script didn't get the vehicle id?!): Bad argument @ 'dbQuery'[Expected db connection at argument 1, got string 'SELECT matrica FROM vehicle WHERE id=?'] Link to comment
Dimos7 Posted January 14, 2019 Share Posted January 14, 2019 local result = dbPoll(dbQuery(mysql, "SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")), - 1) if(#result == 1) then dbExec(mysql, "UPDATE vehicle SET paintjob = ? WHERE id = ?", paintjob, vehicle:getData("veh:id")) else outputChatBox ( "Előbb szedd le a matricát!" ) end Link to comment
hipolitalakaj Posted January 14, 2019 Author Share Posted January 14, 2019 Thanks for your help! , now works without error in debugscript ,but still not working properly. Always says the outputchatbox thing "Előbb szedd le a matricát!" if the matrica row value is 0 in the vehicle table. I think you didn't get it what I want. I want to do when the matrica row value is 1,2 or 3 in the vehicle table then outputchatbox say "Előbb szedd le a matricát!" and ignore the update command. but if the matrica row value is 0 in the vehicle table then do the update command. Link to comment
Dimos7 Posted January 14, 2019 Share Posted January 14, 2019 local result = dbPoll(dbQuery(mysql, "SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")), - 1) if(#result >= 1) then dbExec(mysql, "UPDATE vehicle SET paintjob = ? WHERE id = ?", paintjob, vehicle:getData("veh:id")) else outputChatBox ( "Előbb szedd le a matricát!" ) end Link to comment
hipolitalakaj Posted January 14, 2019 Author Share Posted January 14, 2019 Now I get nothing in chatbox if the matrica row value 1,2,3 or more ... and the paintjob applys. Link to comment
Dimos7 Posted January 14, 2019 Share Posted January 14, 2019 local result, num_affected_row= dbPoll(dbQuery(mysql, "SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")), - 1) if(num_affected_row >= 1) then dbExec(mysql, "UPDATE vehicle SET paintjob = ? WHERE id = ?", paintjob, vehicle:getData("veh:id")) else outputChatBox ( "Előbb szedd le a matricát!" ) end Link to comment
hipolitalakaj Posted January 14, 2019 Author Share Posted January 14, 2019 Nothing changes. I think something wrong. The code doesn't care the number in the matrica row... if I change the matrica row to 0 the script just say the output thing, if I change to 1,2,3 same. The matrica row type is int(2) if it matters. Link to comment
savour Posted January 14, 2019 Share Posted January 14, 2019 dbQuery returns a query handle and not the final usable value, instead, it pass it to a callBackFunction, in this case dbPoll can handle it also, it returns a table of the results which is you already put in there, means that if you want to get the colors of this vehicle id from the db you first must've inserted it there. try outputChatBox(vehicle:getData("veh:id")) and see the results, then try local result = dbPoll(dbQuery(mysql, "SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")), - 1) if(#result >= 1) then for i, v in ipairs(result) do outputChatBox("Result #"..i..": "..v) end else outputChatBox ( "No data were found that matching the query case" ) end if you got the last message that means you don't have any data stored in your database matching that given arguement Link to comment
hipolitalakaj Posted January 14, 2019 Author Share Posted January 14, 2019 (edited) Quote try outputChatBox(vehicle:getData("veh:id")) I got the vehcicle id in which I've be (23) I'm trying to add to an eventhandler and get this error: attempt to to concatenate local 'v' (a table value) addEvent("tuning->Paintjob", true) addEventHandler("tuning->Paintjob", root, function(vehicle, paintjob) local result = dbPoll(dbQuery(mysql, "SELECT matrica FROM vehicle WHERE id=?", vehicle:getData("veh:id")), - 1) if(#result >= 1) then for i, v in ipairs(result) do outputChatBox("Result #"..i..": "..v) end else outputChatBox ( "No data were found that matching the query case" ) end end) Edited January 14, 2019 by hipolitalakaj provided wrong info before Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now