Jump to content

Problem Mysql " Where= "


Ascla

Recommended Posts

Hey guys,

I'm new here, but i'm trying to make my own script for my rp server.

So, i want set in my database the engine status of my car, but when the server execute the command, it changes each car's engine.

Exemple : when i stop my engine, it will set OFF, for each cars of the map.

My script :

  
  
function _changeEngineState( thePlayer ) 
local theVehicle = getPedOccupiedVehicle ( thePlayer ) 
 if ( theVehicle ) then 
  if ( getPedOccupiedVehicleSeat( thePlayer ) == 0 ) then 
  local vehicleID = getElementData( theVehicle, "vehicleID" ) 
   local result = mysql_query ( database ,"SELECT * FROM `vehicles` WHERE `vehicleID` = '"..tonumber(vehicleID).."'") 
    if result then 
     if ( getVehicleEngineState( theVehicle ) == true) then 
      setVehicleEngineState( theVehicle, false ) -- turn it off. 
      setElementData( theVehicle, "moteur", 0) 
      mysql_query(database,"UPDATE `vehicles` WHERE vehicleID='"..vehicleid.."' SET enginestate = '0'") 
     elseif ( getVehicleEngineState( theVehicle ) == false)  then 
      setVehicleEngineState( theVehicle, true ) -- turn it on 
      setElementData( theVehicle, "moteur", 1) 
      mysql_query(database,"UPDATE `vehicles` WHERE vehicleID='"..vehicleid.."' SET enginestate = '1'") 
     end 
    end 
  end 
 end 
end 
addCommandHandler("moteur", _changeEngineState) 
  
  

Edited by Guest
Link to comment

isnt the syntax "UPDATE

SET [col=value,col2=value2] WHERE [statement]"? (rhetorical)

odd that it blatantly updates them all then, you should really run mysql in safe mode

check if this works:

  
function _changeEngineState( thePlayer ) 
local theVehicle = getPedOccupiedVehicle ( thePlayer ) 
 if ( theVehicle ) then 
  if ( getPedOccupiedVehicleSeat( thePlayer ) == 0 ) then 
  local vehicleID = getElementData( theVehicle, "vehicleID" ) 
   local result = mysql_query ( database ,"SELECT * FROM `vehicles` WHERE `vehicleID` = '"..tonumber(vehicleID).."'") 
    if result then 
     if ( getVehicleEngineState( theVehicle ) == true) then 
      setVehicleEngineState( theVehicle, false ) -- turn it off. 
      setElementData( theVehicle, "moteur", 0) 
      mysql_query(database,"UPDATE `vehicles`  SET enginestate = '0' WHERE vehicleID='"..vehicleid.."'") 
     elseif ( getVehicleEngineState( theVehicle ) == false)  then 
      setVehicleEngineState( theVehicle, true ) -- turn it on 
      setElementData( theVehicle, "moteur", 1) 
      mysql_query(database,"UPDATE `vehicles`  SET enginestate = '1' WHERE vehicleID='"..vehicleid.."'") 
     end 
    end 
  end 
 end 
end 
addCommandHandler("moteur", _changeEngineState) 
  

Link to comment

Thanks a lot ! It works good. I love you <3

function _changeEngineState( thePlayer ) 
local theVehicle = getPedOccupiedVehicle ( thePlayer ) 
 if ( theVehicle ) then 
  if ( getPedOccupiedVehicleSeat( thePlayer ) == 0 ) then 
  local vehicleID = getElementData( theVehicle, "vehicleID" ) 
   local result = mysql_query ( database ,"SELECT * FROM `vehicles` WHERE `vehicleID` = '"..tonumber(vehicleID).."'") 
    if result then 
     if ( getVehicleEngineState( theVehicle ) == true) then 
      setVehicleEngineState( theVehicle, false ) -- turn it off. 
      setElementData( theVehicle, "moteur", 0) 
      mysql_query(database,"UPDATE `vehicles`  SET enginestate = '0' WHERE vehicleID='"..vehicleID.."'") 
     elseif ( getVehicleEngineState( theVehicle ) == false)  then 
      setVehicleEngineState( theVehicle, true ) -- turn it on 
      setElementData( theVehicle, "moteur", 1) 
      mysql_query(database,"UPDATE `vehicles`  SET enginestate = '1' WHERE vehicleID='"..vehicleID.."'") 
     end 
    end 
  end 
 end 
end 
addCommandHandler("moteur", _changeEngineState) 

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