Jump to content

MySQL if row value 1


hipolitalakaj

Recommended Posts

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
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

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
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
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

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
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 by hipolitalakaj
provided wrong info before
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...